-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: Version 3.0.0-dev.20180601 and also Version 2.9.1
Search Terms: ES5 generator this value
Code
class Test {
async getChildren() {
const randomItems = await this.someRandomMethod();
const processedItems = randomItems.map((item) => {
return this.doSomeProcessing(item); // <-- this will have incorrect _this value!
});
return ([] as string[]).concat(...processedItems); // <-- if I don't cast here, the above _this is good
}
private doSomeProcessing(stuff: string) {
return stuff;
}
private async someRandomMethod() {
return ["a", "b", "c"];
}
}Expected behavior:
this.doSomeProcessing(item) points to a correct this value
Actual behavior:
The emitted code has var _this = this but in the wrong scope
IanYates, fgambino, timocov and ezhukovskiy
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue