Skip to content

Instantly share code, notes, and snippets.

@millsp
Created May 17, 2021 17:43
Show Gist options
  • Save millsp/cfefce1977bdd347b32cb51e5f59390d to your computer and use it in GitHub Desktop.
Save millsp/cfefce1977bdd347b32cb51e5f59390d to your computer and use it in GitHub Desktop.
Unionize Deep
type MarkUndefinable<A, B> = {
[K in keyof A]: A[K] extends O.Object
? MarkUndefinable<A[K], A.At<B, K>>
: K extends keyof B ? A[K] | undefined : A[K]
}
type UnionizeDeep<A extends object, B extends object> =
O.Merge<MarkUndefinable<A, B>, B, 'deep', M.BuiltIn, undefined>
type test = A.Compute<UnionizeDeep<{
name?: string,
age?: string,
details: {
ccn: string,
address: {
no: string
name: string
}
}
}, {
name: {
first: string
last: string
},
age?: number,
details: {
ccv: string
address: {
no: number
name: string
}
}
}>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment