I have the following code
interface BaseA {
a: number;
}
interface SpecialA extends BaseA {
b: number;
}
type A = BaseA | SpecialA
const a = {
a: 5, b: 5
} as A
console.log(a.b)
I expected the code to be valid, but im getting the error
Property 'b' does not exist on type 'A'.
Property 'b' does not exist on type 'BaseA'
It seems the type A is not what i was trying to define, i was expecting it to be equivelent to the following type
interface A {
a: number;
b?: number;
}
My questions are
- why is the type A i defined different from the type A i expected to get?
- how can i define the expected type A without defining it by hand?
Note: i need to use the type SpecialA as is in some places, so not defining it and just defining expected A is not an option.