Skip to content

Instantly share code, notes, and snippets.

@babakness
Created December 24, 2018 19:35
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 babakness/82eba31701195d9b68d4119a5c59fd35 to your computer and use it in GitHub Desktop.
Save babakness/82eba31701195d9b68d4119a5c59fd35 to your computer and use it in GitHub Desktop.
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