typescript-utility-types
Collection of generic types for TypeScript, complementing built-in mapped types and aliases.
Installation
- Install package
npm install --save-dev typescript-utility-types
- Add reference to your
<type definition file>.d.ts
///
Or:
;
Typescript compatibility
- v3 - minimum TS v3.6.0
Table of content
Dictionary
Dictionary
is variable object type.
Usage:
; obj =; // Ok obj =; // Ok
XOR<A, B>
XOR
will create exclusive set where you can set only one or other type
Usage:
; ; result =; // Ok result =; // Ok result =; // Error
OneOf<A, B>
(same as XOR)
OneOf
will create exclusive set where you can set only one or other type
Usage:
; ; result =; // Ok result =; // Ok result =; // Error
Extend<A, B>
Extend
will extend A type with B type
usage:
; // Will result in ;
Subtract<A, B>
Subtract
will subtract B type from A type
Usage:
; // Will result in ;
Nullable<A>
Nullable
will make possible to assign null to variable.
Usage:
; test = 'Will work';
RecordObject<A, B>
RecordObject
creates type for object which each key has same type.
Usage:
;
ValuesOf<A>
ValuesOf
Returns values of constant array as type.
Usage:
; ; // 'test' | 'of' | 'values';