Closed
Description
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
interface hasMethods {
remove(): void
getExports(key: string): {[key: string]: any} | undefined
}
let obj: hasMethods = {
remove: () => { },
getExports: () => undefined
}
;(function () {
let x = obj.getExports('test')
if (!x) return
// No error, as expected
x.test()
// Error, x might be undefined
obj.remove = () => x.test()
}())