Last active
January 21, 2018 09:38
-
-
Save zheeeng/82aba3a39fb37a3c7e2c7bf539edde0a to your computer and use it in GitHub Desktop.
Advanced TS Type
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
| type Readonly<T> = { | |
| readonly [P in keyof T]: T[P]; | |
| } | |
| type Partial<T> = { | |
| [P in keyof T]?: T[P]; | |
| } | |
| type Nullable<T> = { | |
| [P in keyof T]: T[P] | null; | |
| } | |
| type Proxy<T> = { | |
| get(): T; | |
| set(value: T): void; | |
| } | |
| type Pick<T, K extends keyof T> = { | |
| [P in K]: T[P]; | |
| } | |
| type Record<K extends string, T> = { | |
| [P in K]: T; | |
| } | |
| type Diff<T extends string, U extends string> = | |
| ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; | |
| type Overlap<T extends string, U extends string> = Diff<T, Diff<T, U>>; | |
| type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; | |
| type Overwrite<T, U> = Omit<T, Diff<keyof T, Diff<keyof T, keyof U>>> & U; | |
| type Purify<T extends string> = { [P in T]: T; }[T]; | |
| type NonNullable<T> = T & {}; | |
| type Required<T> = { | |
| [P in Purify<keyof T>]: NonNullable<T[P]>; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment