-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
TypeScript Version:
Version 1.9.0-dev.20160619-1.0
Code
function doThing (x?: { prop: boolean }) {
if (x == null) {
return function () {
throw new TypeError('Not correctly set up')
}
}
return function () {
return x.prop
}
}
{
"compilerOptions": {
"strictNullChecks": true
}
}
Expected behavior: Successful compilation.
Actual behavior:
index.ts(9,12): error TS2532: Object is possibly 'undefined'.
I honestly wasn't sure what this exact feature would be called to find a duplicate, and I know I've logged a similar issues issues in the past. Let me know if a duplicate does exist. In any case, I would expect flow control to have understood the undefined case was already handled. I suppose this could be related to the fact the arguments are mutable? Is it possible to use flow control analysis to understand nothing re-assigns the value (in fact, nothing else even executes) after that return?
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript