I have the following code:
interface A {}
interface B {}
let a: A;
let b: B;
// I want this to fail to compile
a = b;
Because interfaces A
and B
look the same it compiles just fine. How can I define variable a
such that a = b
fails to compile because the types are different?
Typescript 4.7.4.
These interfaces (shapes) overlap, so even though a: A, it can still be assigned to b: B.
interface A {
type: 'A'
}
interface B {
type: 'B'
}
let a: A;
let b: B;
// fails
a = b;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments