Typescript Types
A utility types library for Typescript.
Types
The types included in this library are categorized by their purpose.
Definition Types
| Type | Description |
|---|---|
Primitive |
A union of the primitive types of TypeScript. |
BuiltIns |
A union of the built-in types of TypeScript. |
NonContainerType |
A union of types, whose primary pourpose is not holding other types. |
Boolean Operator Types
| Type | Description |
|---|---|
And<A, B> |
true if A and B (both extend boolean) are both true. |
Not<A> |
true if A (extends boolean) is false and vice-versa. |
Or<A> |
true if either A or B (both extend boolean) is true. |
Xor<A, B> |
true if A and B (both extend boolean) are not both false/true. |
Test Types
| Type | Description |
|---|---|
Extends<A, B> |
true if A extends B, false otherwise1 . |
ExtendsExactly<A, B> |
true if A extends B, false otherwise2 . |
IsAny<T> |
true if T is any, false otherwise (null, undefined also yield false) |
IsNever<T> |
true if T is never, false otherwise (null, undefined, any also yield false) |
IsUndefined<T> |
true if T is undefined, false otherwise (null, never, any also yield false). |
IsUnknown<T> |
true if T is unknown, false otherwise (null, never, any also yield false). |
If<Test, TrueBranch, FalseBranch> |
Returns TrueBranch if Test is true, FalseBranch otherwise[^if_remark]. |
IsKeyOf<T, K> |
true if K is a key of T, false otherwise. If T is any, any K but never will yield true. |
IsEmptyString<S> |
true if S is the empty string '', false otherwise.[^is-empty-string_remark] |
Extraction Types
| Type | Description |
|---|---|
Get<O, P> |
Extract the type of the item at keypath P in object O. |
KeyPaths<T, O, F> |
A union of all keypaths of T where the value does not extend F. Separator can be set via O['separator']. |
OptionalKeysOf<T> |
A union of all keys of T that are marked as optional. If T is a union, a union of the optional keys of all union members of T is returned3 . |
PickAssignable<T, K> |
Return a mapped type with all keys of T that extend K. If no key does extend K an empty type is returned. |
Conversion Types
| Type | Description |
|---|---|
KeyPath<T, Separator = '.'> |
Converts a Separator separated string into a tuple of its parts. |
Simplify<T, E, I> |
Maps types that extend I and not E to their properties. Helps diagnostic messages to be clearer. |
Combination Types
| Type | Description |
|---|---|
Assign<Shape, Defaults, Obj> |
Return a type with the structure of Shape and value types from Obj or Default for missing optional keys in Obj. |
Concat<Prefix, Suffix, Separator> |
Concatenate Prefix and Suffix and - if both are non empty strings - separate them using Separator. |