typelab / aliases
Handy TypeScript type aliases for everyday things like arrays, objects, functions, and promises. It also includes special cases like primitive, nullable, nullish, and undefinable types.
| Type Alias | Description |
|---|---|
|
Type that refers to Useful for bypass lint or type coverage checks. Please use only in circumstances that require it. See *this link*. Remarks Basically the same as TypeScript's built-in It's better to not use |
|
|
Type that refers to Useful for bypass lint or type coverage checks. Please use only in circumstances that require it. See *this link*. Remarks Basically the same as TypeScript's built-in It's better to not use |
|
|
Type that represents an array with elements of type Example // MyArray is string[]
type MyArray = Array<string>; |
|
|
Alias for `Array`. |
|
|
Alias for `Array`. |
|
|
Alias for `Array`. |
|
|
Alias for `Array`. |
|
|
Alias for `Array`. |
|
|
Type that represents a read-only array with elements of type Example // MyReadonlyArray is readonly string[]
type MyReadonlyArray = ReadonlyArray<string>; |
|
|
Alias for `ReadonlyArray`. |
|
|
Alias for `ReadonlyArray`. |
|
|
Type that represents a tuple, which is a fixed-length array of elements of type Example // MyTuple is [number, string]
type MyTuple = Tuple<[number, string]>; |
|
|
Alias for `Tuple`. |
|
|
Type that represents a read-only tuple, which is a fixed-length, immutable array of elements of type Example // MyReadonlyTuple is readonly [number, string]
type MyReadonlyTuple = ReadonlyTuple<[number, string]>; |
|
|
Type that represents a class constructor that takes specified parameters types and returns an instance of a specified type. Example // C is a class
// with constructor(id: number, name: string)
// and {id: number, name: string} as instance and prototype
type C = Class<[id: number, name: string], {id: number, name: string}>; |
|
|
Type that represents falsy value. This includes |
|
|
Type that represents a function that takes specified parameters types and returns a specified type. Example // MyFunction is (param_0: number, param_1: string) => string
type MyFunction = Function<[number, string], string>; |
|
|
Alias for `Function`. |
|
|
Type that represents an async function that takes specified parameters types and returns a specified type. Example // MyAsyncFunction is (param_0: number, param_1: string) => Promise<string>
type MyAsyncFunction = AsyncFunction<[number, string], string>; |
|
|
Alias for `AsyncFunction`. |
|
|
Type that represents a newable function that takes specified parameters types and returns a specified type. Example // MyNewableFunction is new (param_0: number, param_1: string) => string`
type MyNewableFunction = NewableFunction<[number, string], string>; |
|
|
Alias for `NewableFn`. |
|
|
Represents positive infinity in TypeScript as a constant value. Not a real type for javascript built-in |
|
|
Represents negative infinity in TypeScript as a constant value. Not a real type for javascript built-in |
|
|
Represents positive or negative infinity in TypeScript as a constant value. Not a real type for javascript built-in Not a real type for javascript built-in |
|
|
Type that refers to See this link. Example const example: NonNullish = true; // valid
const example2: NonNullish = true as boolean | null; // invalid
const example3: NonNullish = null || undefined; // invalid |
|
|
Type that allows a value to be Example const example: Nullable<string> = null; // valid
const example2: Nullable<string> = undefined; // invalid |
|
|
Type that allows a value to be Example const example: Nullish = null; // valid
const example2: Nullish = undefined; // valid |
|
|
Extended TypeScript `Record` to define a generic Example // ObjNumber is { [x: string]: number; [x: number]: number; [x: symbol]: number; }
type ObjNumber = ObjectGeneric<number>;
const Valid: ObjNumber = { a: 1, b: 2 };
const Invalid: ObjNumber = { a: '1', b: '2' }; // Type 'string' is not assignable to type 'number' |
|
|
Extended TypeScript `Record` to define a empty Example // ObjEmpty is { [x: string]: never; [x: number]: never; [x: symbol]: never; }
type ObjEmpty = ObjectEmpty;
const Valid: ObjEmpty = {};
const Invalid: ObjEmpty = { a: 1 } // Type 'number' is not assignable to type 'never' |
|
|
Extended TypeScript `Record` to define an Example // ObjArrayLike is { [x: number]: string; }
type ObjArrayLike = ObjectArrayLike<string>;
const Valid: ObjArrayLike = { 0: 'first', 1: 'second' };
const Invalid: ObjArrayLike = { 0: 'first', a: 'second' }; // a is invalid key |
|
|
Type that represents any primitive value. This includes Example const value1: Primitive = ""; // valid
const value2: Primitive = {}; // invalid |
|
|
Built-in `Promise` with default type. Example // AsyncValue is Promise<string>
type AsyncValue = Async<string>; |
|
|
Type that allows a value to be Example const example: Undefinable<string> = undefined; // valid
const example2: Undefinable<string> = null; // invalid |
|
|
Type that refers to Useful for bypass lint. Remarks Basically the same as TypeScript's built-in It's better to not use |