- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
I'm basically reopenning
#10642 since the justification provided for the expected behavior doesn't apply in my case.
Here's a playground, be sure to turn on strictNullChecks:
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms:
- strictNullChecks
- control-flow
- undefined
- higher-order function (map, filter, forEach)
- "Object is possibly 'undefined'"
Code
const map = new Map<string, {attr: number}>(); let obj = map.get('key'); if (!obj) { obj = { attr: 1 }; } [].map(elem => { console.log(obj.attr); // error occurs on this line })
Expected behavior:
TypeScript should detect that there's no way obj can become undefined during the evaluation of the map
call.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created