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
classBase2{foo(){returnthis;}}classDerived2extendsBase2{// 'foo' implicitly has return type 'any' because it does not have a // return type annotation and is referenced directly or indirectly in // one of its return expressions.foo(){return<Derived2>super.foo();}}
I'm aware that a bug with implicit-any and recursive methods has been fixed, but to me it's pretty clear that the return value for Derived2.foo is Derived2.
The issue is not no-implicit-any. The problem is the compiler was resolving g the type of Dervived2, that is trying to build a structure for how objects of this type look like. It figured that it has a foo method, then it tried to get the signature for it. Since it does not have a return type annotation, the compiler then needs to look at all return statements to get the return type. In this case it is the type assertion that defines the type. Now here is the issue we do not really know what dervided2 is, cause we were just trying to figure this our. In these situations the compiler breaks the tie by giving it an any type.
The warning basically tells you the compiler could not infer the type as you write it and set it to any. An explicit type annotation should do the trick.
Hopefully we will eventually figure something more concrete out here, but for now the compiler is still in a recursive type inference situation when it is trying to decide whether or not the operand of the type assertion is assignable to the asserted type, which triggers a 'recursive any'.
Activity
mhegazy commentedon Nov 13, 2014
The issue is not no-implicit-any. The problem is the compiler was resolving g the type of Dervived2, that is trying to build a structure for how objects of this type look like. It figured that it has a foo method, then it tried to get the signature for it. Since it does not have a return type annotation, the compiler then needs to look at all return statements to get the return type. In this case it is the type assertion that defines the type. Now here is the issue we do not really know what dervided2 is, cause we were just trying to figure this our. In these situations the compiler breaks the tie by giving it an any type.
The warning basically tells you the compiler could not infer the type as you write it and set it to any. An explicit type annotation should do the trick.
Hope that helps.
RyanCavanaugh commentedon Nov 26, 2014
Hopefully we will eventually figure something more concrete out here, but for now the compiler is still in a recursive type inference situation when it is trying to decide whether or not the operand of the type assertion is assignable to the asserted type, which triggers a 'recursive any'.