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
constfindFive=(array: number[])=>array.find((n)=>n===5);constarrays=[[1],[2,3],[4,5,6]];letmaybeAFive: number|undefined=undefined;// `maybeAFive` is being assigned a `number | undefined` within an array method's callback.arrays.find((array)=>(maybeAFive=findFive(array)));// It is still typed as `undefined` despite the assingment above.maybeAFive;// Imperative equivalent of the `.find()` call above.for(constarrayofarrays){maybeAFive=findFive(array);if(maybeAFive)break;}// Typed `number | undefined`, as expected.maybeAFive;
🙁 Actual behavior
Assignments inside array methods' callbacks are not taken into account for the purpose of typing variables.
🙂 Expected behavior
Assignments inside array methods' callbacks should be taken into account for the purpose of typing variables.
The text was updated successfully, but these errors were encountered:
@IllusionMH You are right, there is a "Types Not Correct in/with Callback" template.
That issue should mention "callback" somewhere in its title.
Anyway thanks for the answer.
Bug Report
Assignments inside array methods' callbacks are not taken into account for the purpose of typing variables.
There are many issues on array methods, eg: #16069, but I couldn't find a duplicate (original?).
🔎 Search Terms
array method callback
🕗 Version & Regression Information
The bug can be found in any version of the TypeScript Playground (currently from v3.3.3333 to 4.9.4, including the Nightly v5.0.0-dev.20221212).
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Assignments inside array methods' callbacks are not taken into account for the purpose of typing variables.
🙂 Expected behavior
Assignments inside array methods' callbacks should be taken into account for the purpose of typing variables.
The text was updated successfully, but these errors were encountered: