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
Observed in 3.7.5 - 4.5.5 (latest) + nightly as of issue filing.
Prior versions claim an error but aren't as specific; there's no reason to believe this is a regression.
exportclassMyClass{typescriptCopyExample(): Array<string>{conststringsToCopy=['a','b','c'];letresult: Array<string>=[];while(stringsToCopy.length>0){result.push(stringsToCopy.pop());// Error: 'string | undefined' is not assignable to parameter of type 'string'}returnresult;}}
🙁 Actual behavior
An error on the flagged line that the result of pop() could be undefined, which is what happens when the array is empty, even inside a conditional check that this is not the case.
🙂 Expected behavior
Inside the conditional check, stringsToCopy is narrowed to an array of length > 0. The return type of pop() and shift() operations are not flagged as possibly undefined.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
array pop shift undefined length
🕗 Version & Regression Information
Observed in 3.7.5 - 4.5.5 (latest) + nightly as of issue filing.
Prior versions claim an error but aren't as specific; there's no reason to believe this is a regression.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
An error on the flagged line that the result of
pop()
could be undefined, which is what happens when the array is empty, even inside a conditional check that this is not the case.🙂 Expected behavior
Inside the conditional check,
stringsToCopy
is narrowed to an array of length > 0. The return type ofpop()
andshift()
operations are not flagged as possiblyundefined
.The text was updated successfully, but these errors were encountered: