typelab / assertions
Handy TypeScript type checks for figuring out what a type is. Includes helpers for things like arrays, objects, functions, primitives, and special cases like null, undefined, union types, and more.
| Type Alias | Description |
|---|---|
|
Checks if a given type Example type Valid = IsAny<any>; // true
type Invalid = IsAny<string>; // false |
|
|
Checks if a given type Example type Valid = IsArray<string[]>; // true
type Invalid = IsArray<string>; // false |
|
|
Checks if a given type Example type Valid = IsArrayWritable<string[]>; // true
type Invalid = IsArrayWritable<readonly string[]>; // false |
|
|
Checks if a given type Example type Valid = IsArrayReadonly<readonly string[]>; // true
type Invalid = IsArrayReadonly<string[]>; // false |
|
|
Checks if a given type Example type Valid = IsTuple<[string]>; // true
type Invalid = IsTuple<string[]>; // false |
|
|
Checks if a given type Example type Valid = IsTupleWritable<[string]>; // true
type Invalid1 = IsTupleWritable<readonly [string]>; // false
type Invalid2 = IsTupleWritable<string[]>; // false |
|
|
Checks if a given type Example type Valid = IsTupleReadonly<readonly [string]>; // true
type Invalid1 = IsTupleReadonly<[string]>; // false
type Invalid2 = IsTupleReadonly<readonly string[]>; // false |
|
|
Checks if a given type Example type Valid = IsBigInt<bigint>; // true
type Invalid = IsBigInt<number>; // false |
|
|
Checks if a given type Example type Valid = IsBigIntLiteral<1n>; // true
type Invalid = IsBigIntLiteral<bigint>; // false |
|
|
Checks if a given type Example type Valid = IsBoolean<boolean>; // true
type Invalid = IsBoolean<string>; // false |
|
|
Checks if a given type Example type Valid = IsFalse<false>; // true
type Invalid = IsFalse<boolean>; // false |
|
|
Checks if a given type Example type Valid = IsFalsy<false | '' | 0 | 0n | null | undefined | void>; // true
type Invalid = IsFalsy<0 | 1>; // false |
|
|
Checks if a given type Example type Valid = IsTrue<true>; // true
type Invalid = IsTrue<boolean>; // false |
|
|
Checks if a given type Example type Valid = IsTruthy<0 | 1>; // true
type Invalid = IsTruthy<0 | 1>; // false |
|
|
Checks if a given type Example class DummyClass {}
type Valid = IsClass<typeof DummyClass>; // true
type Invalid = IsClass<string>; // false |
|
|
Check the type equality between Example type Equal = IsEqual<string, string>; // true
type NotEqual = IsEqual<string, ''>; // false |
|
|
Check the type inequality between `IsEqual` in reverse. Example type NotEqual = IsNotEqual<string, ''>; // true
type Equal = IsNotEqual<string, string>; // false |
|
|
Type that checks if type Example type Extends = IsExtends<'', string>; // true
type NotExtends = IsExtends<string, ''>; // false |
|
|
Type that checks if type `IsExtends` in reverse. Example type NotExtends = IsNotExtends<string, ''>; // true
type Extends = IsNotExtends<'', string>; // false |
|
|
Alias for `IsExtends`. |
|
|
Alias for `IsNotExtends`. |
|
|
Type that checks if type Example type Mutual = IsExtendsMutually<string, any>; // true
type NotMutual = IsExtendsMutually<string, ''>; // false |
|
|
Type that checks if type Example type NotMutual = IsNotExtendsMutually<string, ''>; // true
type Mutual = IsNotExtendsMutually<string, string>; // false |
|
|
Alias for `IsExtendsMutually`. |
|
|
Alias for `IsNotExtendsMutually`. |
|
|
Type that checks if type Example type Relate = IsExtendsEitherWay<string, ''>; // true
type NotRelate = IsExtendsEitherWay<string, number>; // false |
|
|
Type that checks if type Example type NotRelate = IsNotExtendsEitherWay<string, number>; // false
type Relate = IsNotExtendsEitherWay<string, ''>; // true |
|
|
Alias for `IsExtendsEitherWay`. |
|
|
Alias for `IsNotExtendsEitherWay`. |
|
|
Checks if a given type Example type Valid = IsFunction<() => string>; // true
type Invalid = IsFunction<string>; // false |
|
|
Alias for `IsFunction`. |
|
|
Checks if a given type Example type Valid = IsAsyncFunction<() => Promise<string>>; // true
type Invalid = IsAsyncFunction<() => string>; // false |
|
|
Alias for `IsAsyncFunction`. |
|
|
Checks if a given type Example type Valid = IsNewableFunction<new () => string>; // true
type Invalid = IsNewableFunction<() => string>; // false |
|
|
Alias for `IsNewableFunction`. |
|
|
Checks if type Example type Intersected = IsIntersected<'a' | 'c', 'a' | 'b'>; // true
type NotIntersected = IsIntersected<'c', 'a' | 'b'>; // false |
|
|
Checks if type Example type Intersected = IsIntersected<'a' | 'c', 'a' | 'b'>; // true
type NotIntersected = IsIntersected<'c', 'a' | 'b'>; // false |
|
|
Checks if a given number Example type Valid = IsNegative<-11 | -11n>; // true
type Invalid = IsNegative<11 | 11n>; // false |
|
|
Checks if a given type Example type Valid = IsNever<never>; // true
type Invalid = IsNever<string>; // false |
|
|
Checks if a given type Example type Valid = IsNonNullish<{}>; // true
type Invalid = IsNonNullish<string>; // false |
|
|
Checks if a given type Example type Valid = IsNull<{}>; // true
type Invalid = IsNull<string>; // false |
|
|
Checks if a given type Example type Valid = IsNullable<string | null>; // true
type Invalid = IsNullable<string>; // false |
|
|
Checks if a given type Example type Valid1 = IsNullish<string | null>; // true
type Valid2 = IsNullish<string | undefined>; // true
type Invalid = IsNullish<string>; // false |
|
|
Checks if a given type Example type Valid = IsNumber<number>; // true
type Invalid = IsNumber<string>; // false |
|
|
Checks if a given type Example type Valid = IsNumberLiteral<11>; // true
type Invalid = IsNumberLiteral<number>; // false |
|
|
Checks if a given type Example type Valid = IsNumberDecimal<11.1>; // true
type Invalid = IsNumberDecimal<11>; // false |
|
|
Checks if a given type Example type Valid = IsNumberInteger<11>; // true
type Invalid = IsNumberInteger<11.1>; // false |
|
|
Checks if a given type Example type Valid = IsObject<[]>; // true
type Invalid = IsObject<string>; // false |
|
|
Checks if a given type Example type Valid = IsObjectLiteral<{ a: number; b: string }>; // true
type Invalid = IsObjectLiteral<string[]>; // false |
|
|
Checks if a given type Example type Valid = IsObjectEmpty<{ [x: string]: never }>; // true
type Invalid = IsObjectEmpty<{ a: string }>; // false |
|
|
Checks if a given type Example type Valid = IsObjectArrayLike<{ 0: number; 1: number }>; // true
type Invalid = IsObjectArrayLike<{ 0: number; a: number }>; // false |
|
|
Determines whether the type of Example type Valid = IsOptionalProperty<{ a?: string }, 'a'>; // true
type Invalid = IsOptionalProperty<{ a: string }, 'a'>; // false
type Never1 = IsOptionalProperty<{ a: string }, 'b'>; // never
type Never2 = IsOptionalProperty<{}, 'b'>; // never
type Never3 = IsOptionalProperty<undefined, 'b'>; // never |
|
|
Checks if a given number Example type Valid = IsPositive<11 | 11n>; // true
type Invalid = IsPositive<-11 | -11n>; // false |
|
|
Checks if a given type Example type Valid = IsPrimitive<string>; // true
type Invalid = IsPrimitive<object>; // false |
|
|
Checks if a given type Example type Valid = IsPromise<Promise<string>>; // true
type Invalid = IsPromise<string>; // false |
|
|
Alias for `IsPromise`. |
|
|
Checks if a given type Example type Valid = IsPropertyKey<string>; // true
type Invalid = IsPropertyKey<bigint>; // false |
|
|
Determines whether the type of Example type Valid = IsRequiredProperty<{ a: string }, 'a'>; // true
type Invalid = IsRequiredProperty<{ a?: string }, 'a'>; // false
type Never1 = IsRequiredProperty<{ a: string }, 'b'>; // never
type Never2 = IsRequiredProperty<{}, 'b'>; // never
type Never3 = IsRequiredProperty<undefined, 'b'>; // never |
|
|
Checks if a given type Example type Valid = IsString<string>; // true
type Invalid = IsString<number>; // false |
|
|
Checks if a given type Example type Valid = IsStringLiteral<'str'>; // true
type Invalid = IsStringLiteral<string>; // false |
|
|
Checks if a given type Example type Valid = IsSymbol<symbol>; // true
type Invalid = IsSymbol<string>; // false |
|
|
Checks if a given type Example type Valid = IsUndefinable<string | undefined>; // true
type Invalid = IsUndefinable<string>; // false |
|
|
Checks if a given type Example type Valid = IsUndefined<undefined>; // true
type Invalid = IsUndefined<string>; // false |
|
|
Checks if a given type Example type Valid = IsUnion<string | number>; // true
type Invalid = IsUnion<string>; // false |
|
|
Checks if a given type Example type Valid = IsUnknown<unknown>; // true
type Invalid = IsUnknown<string>; // false |
|
|
Checks if a given type Example type Valid = IsVoid<void>; // true
type Invalid = IsVoid<string>; // false |