Last active
February 12, 2020 14:56
-
-
Save Krisztiaan/c5b8bb4910dd0b2d91aac4653965268b to your computer and use it in GitHub Desktop.
Extra Typescript Types
This file contains 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 ValuesOf<T> = T extends { [key: string]: infer T } ? T : never | |
// type Parameters<T> = T extends (...args: infer T) => any ? T : never | |
type FirstParameter<T> = T extends (first: infer T, ...args: any) => any ? T : never | |
type SecondParameter<T> = T extends (first: any, second: infer T, ...args: any) => any ? T : never | |
type PromiseValue<T> = T extends Promise<infer U> | |
? U | |
: T extends (...args: any[]) => Promise<infer U> | |
? U | |
: T | |
type Require<T, P extends keyof T> = T & Required<Pick<T, P>> | |
type NonNullable<T> = Diff<T, null | undefined> | |
type SetStateReturn<T> = Readonly<[T, React.Dispatch<React.SetStateAction<T>>]> | |
type ContextValue<T> = T extends Context<infer U> ? U : undefined | |
type PartiallyRequired<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment