Last active
June 19, 2020 05:26
-
-
Save isthatcentered/7ea87582044f22b74a6d66e9e9262391 to your computer and use it in GitHub Desktop.
Typescript - Deep Partial
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
https://stackoverflow.com/questions/45372227/how-to-implement-typescript-deep-partial-mapped-type-not-breaking-array-properti/49936686#49936686 | |
export type DeepPartial<T> = { | |
[P in keyof T]?: T[P] extends Array<infer U> | |
? Array<DeepPartial<U>> | |
: T[P] extends ReadonlyArray<infer U> | |
? ReadonlyArray<DeepPartial<U>> | |
: DeepPartial<T[P]> | |
}; | |
// Short version to try more, this hasn't caused me problems (yet :D) | |
export type DeepPartial<T> = {[P in keyof T]?: DeepPartial<T[P]>} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment