I have in my TypeScript project a situation which could be simplified with the following:
Consider the following type Type:
type Type = {
a: number;
} | {
a: number;
b: number;
} | {
a: number;
b: number;
c: number;
};
I can define the t constant based on Type type:
const t: Type = {
a: 1,
c: 3
};
And it doesn't give me any error! Due the Type type definition, I couldn't define an object with a and c properties. But I can. Why?
Moreover, if I access c property:
console.log(t.c);
It gives me a transpitation error saying:
Property 'c' does not exist on type 'Type'. Property 'c' does not exist on type '{ a: number; }'.
I really don't know what's going on!