Is there a way to assign a variable to be of type interface A
OR interface B
?
interface A {
foo: string
}
interface B {
bar: string
}
const myVar: A | B = {bar: 'value'} // Error - property 'foo' is missing in type '{ bar: string; }'
How can I set myVar
to conform to either interface A
or interface B
?