I have three different types
type A = 'a'
type B = 'b'
type C = 'c'
I want to type a function either accepts A
, C
or B
, C
but not A
, B
, and C
.
Here is my attempt
type A = 'a'
type B = 'b'
type C = 'c'
type BaseArgs = {
c: C
}
type VariantA = {
a: A
} & BaseArgs
type VariantB = {
b: B,
} & BaseArgs
function fn(arg: VariantA | VariantB) {
}
But turns out it doesn't work as expected, as
const b: B = 'b'
const a: A = 'a'
const c: C = 'c'
fn({b,a,c}) // this would not error out
fn({b,a,c})
should be giving an error but it is not.