Skip to content

Instantly share code, notes, and snippets.

@krotovic
Last active October 11, 2024 10:19
Show Gist options
  • Save krotovic/8c93b315cb57ae5e26816da664193a0f to your computer and use it in GitHub Desktop.
Save krotovic/8c93b315cb57ae5e26816da664193a0f to your computer and use it in GitHub Desktop.
TS DeepPartial
declare type DeepPartial<T, K extends keyof T = keyof T> = { [P in K]?: DeepPartial<T[P]> };
// this includes support for already optional fields
declare type DeepPartial<T> = {
[K in keyof T]?: T[K] extends infer R | undefined ? (R extends object ? DeepPartial<R> : R) : T[K];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment