Typescript: "Potentially invalid reference to 'this' of a class from closure" in constructor?

I get the above error from the "this.addField" command in the constructor. Is that error right? I thought I don't have to bind member methods called in the ctor?

class Foo extends Item {
constructor(someDrilledProp: string) {
super();
this.name = this.addField(someDrilledProp);
}
}
3 comments
Comment actions Permalink

Can't reproduce with similar code

Could you share a complete, self-containing code snippet the issue can be repeated with?

0
Comment actions Permalink

maybe this?

 

class Bar {
x = 4;
constructor() {
this.addField();
}
addField() {
this.x = 5;
}
}
0
Comment actions Permalink

No such errors are reported for me

Can you reproduce the issue in a new project?

 

0

Please sign in to leave a comment.