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
When returning early from a function, types are not inferred correctly in functions defined later in the function. This occurs only with strictNullChecks turned on. Playground.
interfacehasMethods{remove(): voidgetExports(key: string): {[key: string]: any}|undefined}letobj: hasMethods={remove: ()=>{},getExports: ()=>undefined};(function(){letx=obj.getExports('test')if(!x)return// No error, as expectedx.test()// Error, x might be undefinedobj.remove=()=>x.test()}())
The text was updated successfully, but these errors were encountered:
x is a mutable variable. Since x might be mutated at some point, we can't be sure that a reference to x in a callback will still have x defined. (#9998)
In this case you're not actually mutating x, so use const instead. There's a lint rule for that too.
When returning early from a function, types are not inferred correctly in functions defined later in the function. This occurs only with
strictNullChecks
turned on. Playground.TypeScript Version: [email protected], [email protected]
Code
The text was updated successfully, but these errors were encountered: