Skip to content

Issue with declare class fields #242

@BwehaaFox

Description

@BwehaaFox

I'm not entirely sure that the problem is related to this addon specifically, but it is clearly related to the *.gts. files

I have a situation where I need to extend a component from an addon. The addon class has a field interactive and I need to check this field to be true before making any further decisions in the code.

I had this working piece of code in a *.ts file and decided to move it to *.gts.

import SomeAddonComponent from 'some-addon/components/some-component';
import layout from 'some-addon/templates/components/some-component';

class MyComponent extends SomeAddonComponent {
  declare interactive: boolean;
  someFunction() {
    if (this.interactive)
      ...
    super.someFunction(event);
  }
}

export default setComponentTemplate(layout, MyComponent);

declare interactive is used because the linter complains about the absence of the this.interactive field, in order to actually declare the existence of the field forcibly

After changing the extension to *.gts the code stopped working correctly. As a result of debugging, I noticed that this.interactive contains undefined instead of a boolean value. Looking at the prototype of the object, I noticed that the class actually overrides the interactive field, although the *.ts files do not do this.

I perceived declare as part of typescript, so I can’t fully understand, am I using things for other purposes, or is there some kind of conflict with the *.gts files?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions