I'm trying to bind properties of a class to a callback inside that class.
Quick example:
// caller
const first = (): void => {
const testClass = new TestClass();
testClass.second(() => {
console.log(this.member) // error TS2532: Object is possibly 'undefined'
}
}
// TestClass
...
member: string = 'test';
second(cb: () => void) {
const self = this;
cb.bind(self)();
}
this seems to be possibly undefined.
How can I access the classes members from an outside callback?