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: typescript@2.6, typescript@2.7.0-dev.20171102
Code
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()}())
When returning early from a function, types are not inferred correctly in functions defined later in the function. This occurs only with
strictNullChecksturned on. Playground.TypeScript Version: typescript@2.6, typescript@2.7.0-dev.20171102
Code