Closed
Description
TypeScript Version: 2.1.1-rc
Code
class Test {
constructor(public name: string) {
console.log("in ctor:", name);
}
}
const getValue: () => Promise<string> = () => Promise.resolve("test");
const doWork = async () => new Test(await getValue());
doWork().then(test => {
console.log("test:", test);
console.log("name:", test.name);
});
Expected behavior:
Expected the result of getValue to be passed as value to constructors' name parameter.
Actual behavior:
The constructor is called with undefined.
The generated javascript uses the following state machine:
var doWork = function () { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = Test.bind;
return [4 /*yield*/, getValue()];
case 1: return [2 /*return*/, new (_a.apply(Test, [_c.sent()]))()];
}
}); }); };
The result of getValue() is passed to the call to get the constructor (_a.apply) and the actual constructor is called with no arguments (the () at the end)