Created
September 17, 2018 19:01
-
-
Save esamattis/70e9c780e08937cb0b016e04a7422010 to your computer and use it in GitHub Desktop.
Typescript DeepRequired
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 NotNill<T> = T extends null | undefined ? never : T; | |
type Primitive = undefined | null | boolean | string | number | Function; | |
type DeepRequired<T> = T extends Primitive | |
? NotNill<T> | |
: { | |
[P in keyof T]-?: T[P] extends Array<infer U> | |
? Array<DeepRequired<U>> | |
: T[P] extends ReadonlyArray<infer U2> | |
? DeepRequired<U2> | |
: DeepRequired<T[P]> | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 🤩