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
letfoo: string|Array<string>;foo=[];foo.push('');//okconstarr=['a','b','c'];for(constsofarr){foo.push(s);// for of is ok}arr.forEach(s=>{foo.push(s);// error});if(Array.isArray(foo)){arr.forEach(s=>{foo.push(s);// error});}functiontest(){foo.push('');// error, maybe not work in function ?}
π Actual behavior
Type narrowing not work in forEach callback
π Expected behavior
Type narrowing work as expected
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
narrow forEach
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about "common-bugs-that-arent-bugs"
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/FAGwpgLgBAZg9nAXFAzhATgSwHYHMoA+UAguugIYCeAPGlngHwDcww8cUAvFANoC6LNggB0ABwCuKABYAKAORyAlEygB6VXADWrAMZxsaKOTJdec8nIA0UOQCMrNnXIGt46KDL0HoKKHBhGZIpQAN7AUBGwIhLSMijKaqpR7v5QmL5awAC+rMbowm4AouQ6sr6cDKHhkexikmUJ6lBgZHDo2cqsmAEypBSUwul9VDLsisFhkYH5RSVlXJWTUzXR9XGNSS3obdURWZ05bOLYOhCY+lAQYGgyE7tRcHWxChvNrejWALZUtmBQ2HBoAB3NqaNLYWDHU7nCEAfmywCAA
π» Code
π Actual behavior
Type narrowing not work in forEach callback
π Expected behavior
Type narrowing work as expected
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: