Fix circularity error when extending a class in same JSContainer#24710
Conversation
Do this by not widening properties of an object literal that are 1. JS initialisers 2. and not an object literal These properties have types that will never widen, so the compiler shouldn't ask for the types earlier than it strictly needs to.
|
Hmmm. I'm going ahead with the merge of this, even though it doesn't completely fix the problem. Simple cases work fine (like the test I added), but most of the improvement I saw in chrome-devtools-frontend happens because we resolve properties from the base class as having type any. I'll investigate and file separately since this fix works for most cases. |
|
Here is the reduced repro for the part of the problem that's not fixed: var UI = {}
UI.TreeElement = class {
constructor() {
this.treeOutline = 12
}
};
UI.context = new UI.TreeElement();
class C extends UI.TreeElement {
m() {
// should error on these two lines, but doesn't
this.doesNotExist
this.treeOutline.doesntExistEither()
}
};This gives a noImplicitAny error for UI and UI.context (since they reference themselves, they need a type annotation), but no other errors. The error correctly points out that you can annotate The reason for the error is that the fix in this PR still checks the type of any initializer that is not a JSContainer, such as |
Do this by not widening properties of an object literal that are
These properties have types that will never widen, so the compiler shouldn't ask for the types earlier than it strictly needs to. This avoids the bogus circularity error.
Fixes #24703
This reverses the chrome-devtools-frontend errors that #24707 introduces with its improved valueDeclaration location. Together, they provide a substantial improvement to the number of errors we get when compiling that project.