Description
Project A:
// file: foo-a.ts
import BluebirdPromise = require('bluebird');
export async function foo(): BluebirdPromise { } // <== has type annotation
// file: foo-a.js
function foo() {
return __awaiter(this, void 0, BluebirdPromise, function* () { });
}
exports.foo = foo;
Project B:
// file: foo-b.ts
import BluebirdPromise = require('bluebird');
export async function foo() { } // <== no type annotation
// file: foo-b.js
function foo() {
return __awaiter(this, void 0, Promise, function* () { });
}
exports.foo = foo;
These two projects differ only by a single type annotation, but they produce different JavaScript code with different runtime behaviour.
(Compiled with v1.7.3 with target=ES6, module=commonjs, noEmitHelpers=true
).
(Note elison bug #6003 is also visible here but not the subject of this issue.)
Bug or by design?
I understand this is by design (sorry I can't find a better ref).
However I strongly feel this should be considered a bug, because having a "fully erasable, structural type system" is a core design principle of TypeScript (quote is from the design goals page).
If this is tagged as 'by design', could we please get some sort of statement from the team to clarify where TypeScript now stands on the "fully erasable type system" goal and the "[don't] emit different code based on the results of the type system" non-goal?