I've encountered a challenge while attempting to incorporate closures in Typescript within a loop. The issue I'm facing is quite significant.
for(let car of vehicles) {
update(location =>
{
car.location = location;
}
);
}
When compiling using Typescript 1.8.1 and targeting ES5, the following error emerges:
Loop contains block-scoped variable 'car' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.
Using var instead of let in the loop results in all closures utilizing the last value of car. Are there any effective workarounds for this issue when targeting ES5?