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
classProp{value: any;}varx: Prop|null=null;if(x===null){;}elseif(x.value===null){// Line 9x=null;}
tsc -t es5 --strictNullChecks ./foo.ts
Expected behavior:
Compiles.
Actual behavior:
foo.ts(9,10): error TS2531: Object is possibly 'null' or 'undefined'.
If the x = null; assignment (line 10) is removed, it does compile, and x is correctly inferred to be non-null in the condition and body of the else-if block. But this assignment should not have any effect on the nullability of x in the else-if condition.
The text was updated successfully, but these errors were encountered:
Im pretty sure the reason is this: Assignment within a block disabled narrowing within it. If so, the solution is likely already in the works: Control flow based type guards (See PR #6959)
TypeScript Version:
3853bb8 (master after merging #7140 )
Code
tsc -t es5 --strictNullChecks ./foo.ts
Expected behavior:
Compiles.
Actual behavior:
foo.ts(9,10): error TS2531: Object is possibly 'null' or 'undefined'.
If the
x = null;
assignment (line 10) is removed, it does compile, andx
is correctly inferred to be non-null in the condition and body of the else-if block. But this assignment should not have any effect on the nullability of x in the else-if condition.The text was updated successfully, but these errors were encountered: