Allow extending any, without noImplicitAny errors#23153
Conversation
Whenever there is a reference to super, or a reference to a property on `this` that is unknown, you will get an implicit any error.
| const type = nodeCheckFlag === NodeCheckFlags.SuperStatic | ||
| ? getBaseConstructorTypeOfClass(classType) | ||
| : getTypeWithThisArgument(baseClassType, classType.thisType); | ||
| if (noImplicitAny && type.flags & TypeFlags.Any) { |
There was a problem hiding this comment.
Should probably use the helper isTypeAny.
| const type = nodeCheckFlag === NodeCheckFlags.SuperStatic | ||
| ? getBaseConstructorTypeOfClass(classType) | ||
| : getTypeWithThisArgument(baseClassType, classType.thisType); | ||
| if (noImplicitAny && type.flags & TypeFlags.Any) { |
There was a problem hiding this comment.
we do allow you to call a value of type any with no errors under --noImplcitAny, not sure why super would be different..
it seems to me that the error should be in only one place, the extends clause.. since this is the "source" of all the anys that will come later on.
There was a problem hiding this comment.
How is it the source? If you write
declare var Base: any;
class Q extends Base {
constructor() {
super();
}
}
tbqh, none of that should be implicitly any. It's quite explicitly any.
There was a problem hiding this comment.
then we do not need an error altogether..
There was a problem hiding this comment.
Our methodology here was to issue one error per declaration, and not per use.. that is why you only get one error on:
var a; // error
var b = a(); // No error here
var c = a.b.c; // no error hereThere was a problem hiding this comment.
in this PR we are making every reference to super/ this an error.. do not think ppl need that much nagging.. they get it, it is any.
There was a problem hiding this comment.
After some discussion we decided to drop the error. In normal javascript usage, as soon as you turn on --noImplicitAny you will get an error on untyped modules, after which you will have to assume that anything from that module is also of type any.
weswigham
left a comment
There was a problem hiding this comment.
Could you add a version of classExtendingAny.ts with noImplicitAny: false just to verify that these errors do not appear when it's off?
Whenever there is a reference to super, or a reference to a property on
thisthat is unknown, you will get an implicit any error. Previously you would only an error on callingsuper(), but it always appeared, not just with--noImplicitAny.After discussing it with @weswigham and @rbuckton, I decided that an assertion escape hatch for super was too problematic to add.
Edit: After further discussion, we decided to always allow extending any.
Fixes #22443