- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
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: typescript@2.6, typescript@2.7.0-dev.20171102
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() }())
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug