Skip to content

Instantly share code, notes, and snippets.

@peterblazejewicz
Created June 13, 2022 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterblazejewicz/f1ecfcc7ddbe67318fbe9b2cce951047 to your computer and use it in GitHub Desktop.
Save peterblazejewicz/f1ecfcc7ddbe67318fbe9b2cce951047 to your computer and use it in GitHub Desktop.
DeepPartial
type DeepPartial<Thing> = Thing extends Function
? Thing
: Thing extends Array<infer InferredArrayMembmer>
? Array<DeepPartial<Thing>>
: Thing extends object
? DeepPartialObject<Thing>
: Thing | undefined;
type DeepPartialObject<Thing> = {
[Key in keyof Thing]?: DeepPartial<Thing[Key]>;
}
interface Post {
name: string;
message: {
name: string,
author: string,
body: string,
};
id: number;
}
const p: DeepPartial<Post> = {
id: 222,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment