Created
February 6, 2019 21:40
-
-
Save nadeesha/efbb1e68508b4d938dfbec4e6b6cd8ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Make all properties in T optional | |
*/ | |
type Partial<T> = { | |
[P in keyof T]?: T[P]; | |
}; | |
/** | |
* Make all properties in T required | |
*/ | |
type Required<T> = { | |
[P in keyof T]-?: T[P]; | |
}; | |
/** | |
* Make all properties in T readonly | |
*/ | |
type Readonly<T> = { | |
readonly [P in keyof T]: T[P]; | |
}; | |
/** | |
* From T, pick a set of properties whose keys are in the union K | |
*/ | |
type Pick<T, K extends keyof T> = { | |
[P in K]: T[P]; | |
}; | |
/** | |
* Construct a type with a set of properties K of type T | |
*/ | |
type Record<K extends keyof any, T> = { | |
[P in K]: T; | |
}; | |
/** | |
* Exclude from T those types that are assignable to U | |
*/ | |
type Exclude<T, U> = T extends U ? never : T; | |
/** | |
* Extract from T those types that are assignable to U | |
*/ | |
type Extract<T, U> = T extends U ? T : never; | |
/** | |
* Exclude null and undefined from T | |
*/ | |
type NonNullable<T> = T extends null | undefined ? never : T; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment