You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interface FOO {
[key:string]: number
}
declare var foo: FOO | null
if(foo) {
var a = foo['string'] // good
Object.keys(foo).map(key => {
var b = foo[key] // foo cannot possibly be null
})
}
//related
foo && foo['string'] && Object.keys(foo).map(key => {
var a = foo[key] // foo cannot possibly be null
})
Expected behavior:
Should know Object is not 'null'
Activity
AnyhowStep commentedon Jul 30, 2019
It cannot know that
foowon't becomenullinside the function, in the general case.In this specific instance, you can say that the callback is invoked immediately and never invoked again after
.map(), so, it cannot benull.But the compiler can't know that for sure yet
AnyhowStep commentedon Jul 30, 2019
#11498
fatcerberus commentedon Jul 30, 2019
Also see #9998.
typescript-bot commentedon Aug 1, 2019
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.