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
The title probably sounds a bit verbose, but this is a bit of a complicated issue to describe. It's best if I paste some code and explain it.
protectedTest1<T>(val1: T,sel:(T)=>T){returnsel(val1);}protectedTest2<T>(val1: T,sel:(x: T)=> T){returnsel(val1);}protectedTest3(){leta=this.Test1(123, x =>x+123);letb=this.Test2(123, x =>x+123);}
both Test1 and Test2 perform the exact same function. But in Test3a will be typeless (any) and b will be strongly typed to number. The only difference is that Test2 uses a delegate parameter instance variable in the declaration (x). Now that I have found a work around this is less of an issue, but others may want to know about this because it's super annoying writing projector functions that don't return strongly typed results.
The text was updated successfully, but these errors were encountered:
The parameter name T has no relation to the generic type parameter T. So we should expect that a will be any because the type parameter T got two inference candidates: number (via val1) and any (via the return type of the function body, where we computed the return expression of the form any + number to be of type any), between which any is chosen because it is more general.
You may be interested in the --noImplicitAny compiler flag, or the discussion in #5187 and #3081.
Thank you for the explanation, the issue now makes much more sense. I will turn on the flag in my project. I think it definitely makes sense to enable that flag by default to make it an opt out.
The title probably sounds a bit verbose, but this is a bit of a complicated issue to describe. It's best if I paste some code and explain it.
both
Test1
andTest2
perform the exact same function. But inTest3
a
will be typeless (any
) andb
will be strongly typed tonumber
. The only difference is thatTest2
uses a delegate parameter instance variable in the declaration (x
). Now that I have found a work around this is less of an issue, but others may want to know about this because it's super annoying writing projector functions that don't return strongly typed results.The text was updated successfully, but these errors were encountered: