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
functionrepro<T>(_config: {params: T;callback: (params: T)=>(params: T)=>number;}): void{return}repro({params: 1,callback: ()=>{returna=>a+1},// a is unknown});repro({params: 1,callback: _b=>{returna=>a+1},// a is a number, only difference is the ignored outer param});repro({params: 1,callback: ()=>a=>a+1,// a is a number, only difference is the lack of `{ return ... }`});
π Actual behavior
The type of a ends up being unknown, but only if no parameter is declared and a block is used in the outer callback.
π Expected behavior
The type of the inner callback parameter a should be known in all 3 cases.
The text was updated successfully, but these errors were encountered:
classTest{array=[1,2,3]optional?: numberpublicmethodError(): void{if(!this.optional)return;this.array.forEach((x)=>{x=this.optional;// Type 'number | undefined' is not assignable to type 'number'. Type 'undefined' is not assignable to type 'number'.(2322)});}publicmethodOk(): void{this.array.forEach((x)=>{if(!this.optional)return;x=this.optional;});}}
Let me know if this is different problem, then I'll open a new issue.
Bug Report
π Search Terms
callback, block, inference, double
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about arrow functions
β― Playground Link
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAJwKYAdlwDwBUB8AFAPoQLAwDmAXIgN4BQii6AhsqwLYDOtuA3E0QRWAG1EAjVhADWtQmw48+ASkQBefIgXsuvRLjWbEYEJwmpkggL4raANzgwAJvRSooIZEmsMGaTDhCRmZFPVoARgAaIRFxKVl5Iy06d09vRFYNLSyAakQIxGsoxAB6UsRwGTA4AHcwBltBAKxgoTDlApjmOMlpOURiCWy3NHSkLOM8gqKS8sQEUQBPRGcYYGBLVEhURBhuRCgAC12qGrRXDsaVZoxWkJZdTujYsT7E7WTMkenosorFis1hstjs9gdjrtRP0FsBEAADVJjLxIAB06KK8Ou-CAA
π» Code
π Actual behavior
The type of
a
ends up beingunknown
, but only if no parameter is declared and a block is used in the outer callback.π Expected behavior
The type of the inner callback parameter
a
should be known in all 3 cases.The text was updated successfully, but these errors were encountered: