-
Notifications
You must be signed in to change notification settings - Fork 13k
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: 2.2.0-dev.20161112
An async function returning an object with an object spread creates the yield but the wrapping function isn't a generator:
Code
function rootConnection(name: string) {
return {
resolve: async (context, args) => {
const { objects } = await apiService.getMany(name);
return {
...connectionFromArray(objects, args)
};
}
};
}
rootConnection('test');
Compiled into:
function rootConnection(name) {
return __assign({ resolve: (context, args) => {
const { objects } = yield apiService.getMany(name);
return __assign({}, connectionFromArray(objects, args));
} });
}
rootConnection('test');
If I remove the object spread, the compiled code creates a generator wrapper for the yield
Code
function rootConnection(name: string) {
return {
resolve: async (context, args) => {
const { objects } = await apiService.getMany(name);
return {
// ...connectionFromArray(objects, args)
};
}
};
}
rootConnection('test');
Compiled into:
function rootConnection(name) {
return {
resolve: (context, args) => __awaiter(this, void 0, void 0, function* () {
const { objects } = yield apiService.getMany(name);
return {};
})
};
}
rootConnection('test');
Expected behavior:
Generator to wrap the yield
Actual behavior:
No generator, so get an error that yield is a strict reserved word:
const { objects } = yield apiService.getMany(name);
^^^^^
SyntaxError: Unexpected strict mode reserved word
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