Created
December 24, 2018 19:35
-
-
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
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 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