types-kit.mergeexclusive.md
September 4, 2023 ยท View on GitHub
Home > types-kit > MergeExclusive
MergeExclusive type
Create a type that has mutually exclusive keys.
Signature:
export type MergeExclusive<T, U> = IsObject<T | U> extends true
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U
Example
interface Props {
a: number
}
interface Props2 {
b: string
}
let foo: MergeExclusive<Props, Props2>;
foo = { a: 1 } // Works
foo = { b: 'foo' } // Works
foo = { a: 1, b: 'foo'} // Error