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
consta:object[]=[]/*** It can be 'push' 0 or multiple times.* a[] is an array of arbitrary length*/a.push({});a.push({});a.push({});a.push({});a.push({});while(a.length>0){// obj: object | undefinedconstobj=a.pop()// Object is possibly 'undefined'.console.log(obj.toString)}
π Actual behavior
Object is possibly 'undefined'.
I've obviously determined that the a [] length is greater than zero, which means pop cannot return undefined.
But TS is still telling me that obj might be undefined.I had to useconst obj = a.pop()! to make right.
Is this a bug or is ts not implementedοΌ
If not implemented, Why didn't you do it(I'm very interested in it) ?
π Expected behavior
obj type is not included undefined
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
array length narrowing
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Object is possibly 'undefined'.
I've obviously determined that the
a []
length is greater than zero, which meanspop
cannot returnundefined
.But
TS
is still telling me that obj might beundefined
.I had to useconst obj = a.pop()!
to make right.Is this a bug or is ts not implementedοΌ
If not implemented, Why didn't you do it(I'm very interested in it) ?
π Expected behavior
obj
type is not included undefinedThe text was updated successfully, but these errors were encountered: