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
All three compile, or all three complain that .length is being invoked on string | undefined
Actual behavior:
Only (3) complains that error TS2532: Object is possibly 'undefined'. In (1) foo.bar is inferred as string, and thus in (2) bar is also inferred as string. But in (3) bar is string | undefined
I'm actually surprised that a check on foo.bar narrows it down within the if blocks at all, since I remember this only used to narrow bindings. I guess this changed at some point to support narrowing properties, but then it should also narrow (3) identically to (2).
The text was updated successfully, but these errors were encountered:
This is essentially the same as #10065. control flow analysis only narrows the type of the right most symbol. in this case foo.bar; it does not narrow the type of foo to {bar: string}. the first two cases you check on foo.bar and you use foo.bar so no issues, in the third you are looking at the type of foo. since it was not narrowed, you get the original type, and thus bar is still string | undefined.
TypeScript Version: 2.1.0-dev.20160910
Code
tsc -t es5 -m amd --strictNullChecks ./foo.ts
Expected behavior:
All three compile, or all three complain that
.length
is being invoked onstring | undefined
Actual behavior:
Only (3) complains that
error TS2532: Object is possibly 'undefined'.
In (1)foo.bar
is inferred asstring
, and thus in (2)bar
is also inferred asstring
. But in (3)bar
isstring | undefined
I'm actually surprised that a check on
foo.bar
narrows it down within theif
blocks at all, since I remember this only used to narrow bindings. I guess this changed at some point to support narrowing properties, but then it should also narrow (3) identically to (2).The text was updated successfully, but these errors were encountered: