I have the following type declarations:
type Root = { r: string };
type A = { a: string };
type B = { b: string };
type Main = Root & (A | B);
Since Main
is equivalent to {r: string, a: string} | {r: string, b: string}
, this works:
const main: Main = {
r: 'r',
a: 'a'
}
No surprises here. However, this throws the following error:
const func : (main: Main) => void = main => {
main.a
/* ^
* [TS2339]
* Property 'a' doesn't exist on type 'Main'.
* Property 'a' doesn't exist on type 'Root & B' */
}
I do understand that .a
doesn't exist on Root & B
, but it exists on Root & A
, so it must exists on (Root & A) | (Root & B)
which is equivalent to Main
, right?
Is it a bug, or am I missing something?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…