Bug Report
🔎 Search Terms
possibly undefined array methods predicate mutable variables narrowing
🕗 Version & Regression Information
4.5.4
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about functions and method "bugs" that aren't bugs
⏯ Playground Link
Playground link with relevant code
💻 Code
functiontest(param?: number): number{leta: number|undefined;// Some code that could make a defined goes hereif(a===undefined||param===undefined){return0;}constb=()=>a+param;// a is not narrowed. param is narrowedfunctionc(){// Neither is narrowedreturna+param;}[1,2,3].map(elem=>elem+a+param);// a is not narrowedreturna+param;// Both narrowed}🙁 Actual behavior
The variables are not narrowed when used in functions. param is narrowed when using an arrow function. This causes friction when trying to use an array method that takes a function as an argument
🙂 Expected behavior
Both variables are narrowed to number in all cases
Bug Report
🔎 Search Terms
possibly undefined array methods predicate mutable variables narrowing
🕗 Version & Regression Information
4.5.4
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The variables are not narrowed when used in functions.
paramis narrowed when using an arrow function. This causes friction when trying to use an array method that takes a function as an argument🙂 Expected behavior
Both variables are narrowed to number in all cases