TypeScript error: Initializer of instance member variable cannot reference identifier declared in the constructor.
In a TypeScript application we are building, we have code similar to the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public processAllOrders = () => { | |
system.log("process orders"); | |
var that = this; | |
all([ | |
this.processOrder(), | |
this.processPayment() | |
]).then(function (results) { | |
that.Orders=results; | |
system.log("All orders processed!"); | |
}); | |
}; |
However when we try to run this, TypeScript complains with the following error message:
Error 19 Initializer of instance member variable 'processAllOrders' cannot reference identifier 'that' declared in the constructor.
I think it’s a bug in TypeScript as I don’t see any reason why this shouldn’t work.