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
functiontest<T>(options: {fn1: (t: T)=>void;fn2: (t: T)=>void;}): void{}// Function props - workstest({fn1: t=>{},fn2: (t: string)=>{},});// Methods with annotation first - workstest({fn1(t: string){},fn2(t){},});// Methods with annotation last - doesn't worktest({fn1(t){},fn2(t: string){},});
π Actual behavior
When providing multiple function properties with the same type parameter as a function parameter, the type parameter will always be inferred from the first function property.
π Expected behavior
I'm expecting the explicitly annotated function callbacks to have higher inference priority than the ones without annotations.
Additional information about the issue
Not sure whether this is a bug or intended behavior, but though I'd report it to check. It seems related to #18654, although turning off strict function types doesn't change the behavior, it just removes the type error where the unknown param is not assignable to string.
It also looks like it's related to for example #58746, but slightly different.
The text was updated successfully, but these errors were encountered:
Contextual parameters are assigned in source order and it isn't a unique limitation for callbacks contained in objects. The same happens for arguments lists: TS playground
π Search Terms
"callback inference", "method inference"
π Version & Regression Information
Testing this in the playground it seems to be an issue all the way back to 3.3.3
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.4#code/GYVwdgxgLglg9mABFApgZygHgCoD4AUcADrAmgFyIDeAUIosGAIyX5SXYCUiAvLogDc4MACYBuOgzAAmVu0Rde-IaIkBfTpRUjqamjQD0BxADFw0eEiIAnYmkQBaRAHc41gNZoaqDPlr1GFmQlXQAaSUZZRDZKDGsYMABzbj4wmg0JQ2MAWRQoAAs4EXtnGALEAEMwMDgoCtIkYBhrDEcXN09vdCg-COYYxDiE5LSAmTZuKjVwjP0jRFyCopKy-Mrq2vrLRAAbCtanETh0MAByKHaPLt9-KSYJ0alpAaGkyen0zjEgA
π» Code
π Actual behavior
When providing multiple function properties with the same type parameter as a function parameter, the type parameter will always be inferred from the first function property.
π Expected behavior
I'm expecting the explicitly annotated function callbacks to have higher inference priority than the ones without annotations.
Additional information about the issue
Not sure whether this is a bug or intended behavior, but though I'd report it to check. It seems related to #18654, although turning off strict function types doesn't change the behavior, it just removes the type error where the
unknown
param is not assignable tostring
.It also looks like it's related to for example #58746, but slightly different.
The text was updated successfully, but these errors were encountered: