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
functionprintString(){constmyString: string|null='Hello';if(myString==null){return;}setTimeout(()=>{console.log('String length was '+myString.length);},100);}printString();
Actual behavior:
When compiled with --strictNullChecks, this code fails:
testcase.ts(7,44): error TS2531: Object is possibly 'null'.
Expected behavior:
Null inference works fine within the immediate printString scope, but it's disabled inside closures.
This behavior makes sense for variables, since otherwise I could write something like this, that would make myString actually become null when it's read and fail:
functionprintString(){letmyString: string|null='Hello';if(myString==null){return;}setTimeout(()=>{console.log('String length was '+myString.length);},100);myString=null;}printString();
On the other hand, constants don't allow this, so their non-nullity can be guaranteed if they were checked before the closure was declared.
The text was updated successfully, but these errors were encountered:
TypeScript Version:
1.9.0-dev.20160528-1.0
Code
Actual behavior:
When compiled with
--strictNullChecks
, this code fails:Expected behavior:
Null inference works fine within the immediate
printString
scope, but it's disabled inside closures.This behavior makes sense for variables, since otherwise I could write something like this, that would make
myString
actually become null when it's read and fail:On the other hand, constants don't allow this, so their non-nullity can be guaranteed if they were checked before the closure was declared.
The text was updated successfully, but these errors were encountered: