type-plus
    Preparing search index...

    Interface TestType

    interface TestType {
        any<T>(expected: IsAny<T>): T;
        array<T>(expected: IsArray<T, { exact: true }>): T;
        bigint<T>(expected: IsBigint<T, { distributive: false }>): T;
        boolean<T>(expected: IsBoolean<T, { distributive: false }>): T;
        canAssign<A, B>(expected: Assignable<A, B>): A;
        equal<A, B, C>(expected: IsEqual<A, B> & IsEqual<A, C>): A;
        equal<A, B>(expected: IsEqual<A, B>): A;
        false<T>(expected: IsFalse<T, { distributive: false }>): T;
        function<T>(expected: IsFunction<T, { distributive: false }>): T;
        inspect<T>(handler: (t: InspectedType<T>) => unknown): T;
        never<T>(expected: IsNever<T>): T;
        null<T>(expected: IsNull<T, { distributive: false }>): T;
        number<T>(expected: IsNumber<T, { distributive: false }>): T;
        object<T>(expected: IsObject<T, { distributive: false }>): T;
        strictBigint<T>(
            expected: IsBigint<T, { distributive: false; exact: true }>,
        ): T;
        strictBoolean<T>(
            expected: IsBoolean<T, { distributive: false; exact: true }>,
        ): T;
        strictCanAssign<A, B>(
            expected: Assignable<A, B, { distributive: false }>,
        ): A;
        strictFunction<T>(
            expected: IsStrictFunction<T, { distributive: false }>,
        ): T;
        strictNumber<T>(
            expected: IsNumber<T, { distributive: false; exact: true }>,
        ): T;
        strictString<T>(
            expected: IsString<T, { distributive: false; exact: true }>,
        ): T;
        string<T>(expected: IsString<T, { distributive: false }>): T;
        symbol<T>(expected: IsSymbol<T, { distributive: false }>): T;
        true<T>(expected: IsTrue<T, { distributive: false }>): T;
        tuple<T>(expected: IsTuple<T, { distributive: false }>): T;
        undefined<T>(expected: IsUndefined<T, { distributive: false }>): T;
        unknown<T>(expected: IsUnknown<T>): T;
        void<T>(expected: IsVoid<T, { distributive: false }>): T;
    }
    Index

    Methods

    • Check if A can assign to B.

      If A is a union, the check is distributive.

      Meaning the result can be boolean, meaning both true and false will pass.

      If you want to avoid the distributivity, use testType.strictCanAssign() instead.

      Type Parameters

      • A
      • B

      Parameters

      Returns A

      expected as A for type inspection.

      testType.canAssign<123, number> // true

      testType.canAssign<number | string, number> // boolean
    • A quick way to inspect a type.

      The handler receives a InspectedType object. It contains value which is typed to T, and many other properties to inspect the behavior of T.

      The handler is not being call, it is use to hold the type in value for inspection.

      🧪 testing 🦴 utilities

      Type Parameters

      • T

      Parameters

      Returns T

      testType.inspect<SomeType>(t => {
      type T = typeof t.value // resolve and inspect the type `T`
      t.extend_boolean // result of `T extends boolean`
      })

      After trying out the type, remove the line.

    • Check if A can fully assign to B.

      This checks all branches in an union A are assignable to B.

      Type Parameters

      • A
      • B

      Parameters

      Returns A

      expected as A for type inspection.

      testType.strictCanAssign<number | string, number | string> // true

      testType.strictCanAssign<number | string, number> // false