My challenge is with TypeScript's binding inside a class, where I want to enforce the use of arrow functions during compilation to JavaScript.
Here is the code snippet:
However, when this function is compiled to JavaScript, it throws an error this.method1 is undefined
.
The issue seems to be related to the binding of method2
.
To resolve this, I manually modified the compiled JavaScript file to include the binding of method2
to the class, and it worked as expected.
export class1 {
private method1(){}
public method2(){
this.method1();
}
}
I require method1
to be accessible from method2
, hence why I prefer using arrow functions that do not require explicit binding. My goal is for TypeScript to always compile the code into arrow functions.