Why is code completion for subclasses not working in angular templates?

194 Views Asked by At

For example, when we have 2 array properties on our component:

  • array: an ordinary Array
  • anonymousArray a subclass of Array
export class AppComponent {
  readonly array = new Array<{
    text: string;
    value: string;
  }>();

  readonly anonymousArray = new class extends Array<{
    text: string;
    value: string;
  }> {
    add(text: string, value: string) {
      this.push({
        text,
        value
      });
    }
  }();

  constructor() {
    this.array.push({
      text: "text1",
      value: "value1"
    });

    this.anonymousArray.add("text", "value");
  }
}

Then code-completion in the template works for the ordinary Array:
enter image description here
but not for the sub-class:
enter image description here

Here's a full Stackblitz example

IntelliJ will even show errors:
enter image description here

I wonder how this is possible in the first place: i.e. since Array.isArray(this.anonymousArray) is true, how/why does the template even see a difference?
Is this maybe a bug in Ivy or the angular language service?

1

There are 1 best solutions below

8
On

Works fine for me in the most recent IDEA version:

enter image description here

Edit: appears to be specific to libraries versions being used, tracked at WEB-49995