You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discriminated union does not work with string literal types #37650
const$type: "@type"="@type"typeA={["@type"]: "A",a: boolean}typeB={["@type"]: "B",b: boolean}typeC=A|Bdeclareconstc: C;switch(c[$type]){case"A":
c.a;// <-- Property 'a' does not exist on type 'B'.(2339)}switch(c["@type"]){case"A":
c.a;}
Expected behavior:
No error.
Actual behavior:
Property 'a' does not exist on type 'B'.(2339)
Performance limitation; it's too expensive to put a control flow node on every element access -- creating it uses too much space and walking over it uses too much time. The decision to create a flow node is made syntactically, just after parsing, so there's no type information to guide it.
We have made similarly expensive expansions to control flow analysis before, like the nodes we add to support assert narrowing. But this feature isn't as useful, I think.
Activity
RyanCavanaugh commentedon Apr 1, 2020
Nathan Shively-Sanders (@sandersn) design limitation?
sandersn commentedon Apr 1, 2020
Performance limitation; it's too expensive to put a control flow node on every element access -- creating it uses too much space and walking over it uses too much time. The decision to create a flow node is made syntactically, just after parsing, so there's no type information to guide it.
We have made similarly expensive expansions to control flow analysis before, like the nodes we add to support
assertnarrowing. But this feature isn't as useful, I think.sandersn commentedon Apr 1, 2020
Discussion is here, including a link back to the original bug: #31478