Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler elides import of identifier that is referenced in emitted code. #6003

Closed
yortus opened this issue Dec 9, 2015 · 1 comment
Closed
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created

Comments

@yortus
Copy link
Contributor

yortus commented Dec 9, 2015

// 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.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Dec 9, 2015
@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 9, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Dec 9, 2015

this is duplicate of #5998, it has since been fixed in master. please try typescript@next and let us know if you are still running into other issues.

@mhegazy mhegazy closed this as completed Dec 9, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants