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
interfaceA{foo?: {x: number};bar?: {y: number};}functionf(a: A){if(a.foo&&a.bar){constxx=a.foo.x;constyy=a.bar.y;// No errorconst{foo: { x },bar: { y }}=a;// Error}}
Expected behavior:
No errors.
Actual behavior:
a.ts(9,24): error TS2459: Type '{ x: number; } | undefined' has no property 'x' and no string index signature.
a.ts(9,36): error TS2459: Type '{ y: number; } | undefined' has no property 'y' and no string index signature.
This is a design limitation. The narrowing expression only narrows a.foo and not a itself; so when the destructring happens you still have the undefined. I will try to look up the original issue later for you.
TypeScript Version: nightly (2.3.0-dev.20170313)
Code
Expected behavior:
No errors.
Actual behavior:
May be related: #12620, #6784
The text was updated successfully, but these errors were encountered: