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
{{ message }}
Repository navigation
Incorrect inference for function expression with type annotation and generic #16293
// I can conveniently annotate a function express with a type// This is good because the types don't litter the implementation{typeadd=(a: number)=>(b: number)=>number;constadd: add=a=>b=>a+b;// a and b are type number}// However, if I try to do the same where the function type has a generic…{typefn=<A>(a: A)=>A;constfn: fn=a=>a;// a is inferred as any, but expected A}
Is there any way to annotate the function expression fn with the type fn without breaking inference for the parameters?
Activity
T-Hugs commentedon Jun 6, 2017
Why did you expect number? You don't have
numberanywhere in the second block.OliverJAsh commentedon Jun 6, 2017
trevorsg Sorry, that was a mistake. I would expect to see the parameters typed as the generic,
A, not asany.Even when the generic is constrained, the parameters still show as
any, which is especially misleading:ahejlsberg commentedon Jun 6, 2017
Oliver Joseph Ash (@OliverJAsh) Funny you should ask, I'm working on precisely that right now. Stay tuned for a PR.