-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
// file: foo.ts
import BluebirdPromise from 'bluebird';
export async function foo(): BluebirdPromise { }
// file: foo.js
function foo() {
return __awaiter(this, void 0, BluebirdPromise, function* () { });
}
exports.foo = foo;(Compiled with target=ES6, module=commonjs, noEmitHelpers=true).
The BluebirdPromise import has been elided in the generated code, resulting in "ReferenceError: BluebirdPromise is not defined" at runtime.
The elision occurs because BluebirdPromise only appears in a type position which up until v1.7 meant that the compiler could safely elide it. But the compiler now emits this type annotation into the JavaScript output so that elision assumption is no longer safe.
IMO the problem here is not the elision logic, its the fact that the compiler now emits code that depends on type annotaitons, so the type system no longer enjoys the quality of being fully erasable, which I understood to be a core design principle of the language. I thought the idea of using type annotations to change runtime behaviour would have been smacked down by @ahejlsberg and the team before it got into production.
Regardless of that contended side-topic, I believe this is a bug.