Created
June 13, 2022 20:09
-
-
Save peterblazejewicz/f1ecfcc7ddbe67318fbe9b2cce951047 to your computer and use it in GitHub Desktop.
DeepPartial
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
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