I have the following code:
interface A {
a: string;
}
interface B {
a: string;
b: string;
}
let a: A = {
a: 'test'
}
let b: B = {
a: 'test',
b: 'test2'
}
a = {
a: 'test',
b: 'test' // here I have an error, "b" doesn't exist in A
}
a = b; // but here...NO ERROR?
a; // and it's still A
I'm confused. Why can I assign "a" to "b" without an error but I can't assign "a" to an object of type B at the same time? I thought that it works because I changed the type of "a" when assigning it to the variable "b" of type "B" but "a" is still of type "A", yet it contains property "b" now...
What's the explanation for this? Is it somehow related to references?