Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
generic type and typed function that conditionally extend an object if the keys / value type of the first object are not in the second
type XorExtend<T extends {
[K in keyof T]: K extends keyof A
? A[K] extends T[K]
? never
: T[K]
: T[K]
}, A extends object,> = T & A
declare function xorExtend<O, P extends { [K in keyof P]: K extends keyof O
? O[K] extends P[K]
? never
: P[K]
: P[K]
}>(a: O, b: P): P & O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment