Skip to content

Instantly share code, notes, and snippets.

@lenconda
Forked from navix/readme.md
Created August 4, 2023 09:02
Show Gist options
  • Save lenconda/fbcabfa6c2b4a2fb0d71f77d81ad0ea3 to your computer and use it in GitHub Desktop.
Save lenconda/fbcabfa6c2b4a2fb0d71f77d81ad0ea3 to your computer and use it in GitHub Desktop.
TypeScript Deep Partial Interface

TypeScript Deep Partial Interface

export type DeepPartial<T> = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T);
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]>
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment