Last active
May 4, 2022 21:14
-
-
Save matthewsimo/cd9e80a012fcd738a81df51ac6398d67 to your computer and use it in GitHub Desktop.
Typescript Type Utils
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
export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | |
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never; | |
// expands object types recursively | |
export type ExpandRecursively<T> = T extends object | |
? T extends infer O | |
? { [K in keyof O]: ExpandRecursively<O[K]> } | |
: never | |
: T; | |
export type DeepPartial<T> = { | |
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment