XOR 타입



type TestType = { name: string; age: number;} | { name?: never; age?: never; country: string;  } ;

const test2 : TestType = {
    name: "bug",
    age: 10,
}

const test3 : TestType = {
    country: 'korea;'
}

type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

Last updated

Was this helpful?