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
functionid<T>(v: T): T{returnv;}functionapplyToNumber<T>(v: T,toNumber: (x: T)=>number): number{returntoNumber(v);}applyToNumber(5,v=>v);// okapplyToNumber(5,id);// okapplyToNumber("aaa",v=>v);// error, as expected.applyToNumber("aaa",id);// ok, but an error is expected.
If it's compatibility problem, it would be really helpful to have a "strictTyping" compilation mode which would prohibit converting the any type to other types without explicit cast.
they say without any it will be an infinite recursion which i don't get because an explicit lambda (v => v in your case) doesn't have this problem, if so.. why would not TS handle all function references as explicit lambdas behind the scenes to avoid this recursion problem
Activity
zpdDG4gta8XKpMCd commentedon Oct 11, 2016
might be
dupa new shiny case of #3038sergey-shandar commentedon Oct 11, 2016
If it's compatibility problem, it would be really helpful to have a "strictTyping" compilation mode which would prohibit converting the
anytype to other types without explicit cast.zpdDG4gta8XKpMCd commentedon Oct 11, 2016
they say without
anyit will be an infinite recursion which i don't get because an explicit lambda (v => vin your case) doesn't have this problem, if so.. why would not TS handle all function references as explicit lambdas behind the scenes to avoid this recursion problemsergey-shandar commentedon Oct 11, 2016
An ugly workaround
mhegazy commentedon May 18, 2017
related to #5616, and possibly #417, #5487, #9107, #9659, #9660,
#10247, #11311, #11343, #5616
zpdDG4gta8XKpMCd commentedon May 18, 2017
looks like its time to bite that bullet or else you gonna break that all time record of the number of open issues related to the same problemo
AllainPL commentedon Nov 13, 2017
The sample given:
in TS 2.6 returns error:
So I assume it's fixed.
mhegazy commentedon Nov 13, 2017
thanks! closing.