In the example below:
type TA = { a: 1 }
type TB = { b: 2 }
type TC = { c: 3 }
const testa: TA = {
a: 1
}
const testb: TB = {
b: 2
}
I want to only allow an object with type TA or type TB, not a combined object. The following is allowed in TypeScript:
const testEitherOr: TA | TB | TC = {
a: 1,
b: 2 // This seems like it should not be allowed
}
How can I ensure that test
matches only one of the types?