Skip to content

Instantly share code, notes, and snippets.

@isthatcentered
Last active June 19, 2020 05:26
Show Gist options
  • Save isthatcentered/7ea87582044f22b74a6d66e9e9262391 to your computer and use it in GitHub Desktop.
Save isthatcentered/7ea87582044f22b74a6d66e9e9262391 to your computer and use it in GitHub Desktop.
Typescript - Deep Partial
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