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

emitDecoratorMetadata causes runtime errors by referencing type-only imports #37672

Closed
AlCalzone opened this issue Mar 29, 2020 · 0 comments · Fixed by #39337
Closed

emitDecoratorMetadata causes runtime errors by referencing type-only imports #37672

AlCalzone opened this issue Mar 29, 2020 · 0 comments · Fixed by #39337
Assignees
Labels
Bug A bug in TypeScript

Comments

@AlCalzone
Copy link
Contributor

TypeScript Version: 3.9.0-dev.20200329

Search Terms: emitDecoratorMetadata type import

When combining emitDecoratorMetadata with type-only imports, the generated code crashes at runtime. I've been unable to produce a repro on the playground, since it somehow adds another undefined check, so I'll show you real-world code where this happens:

  1. clone https://github.com/AlCalzone/node-zwave-js/tree/41da020d7515826e3e8fc2e0c3fc24a0d3c19355
  2. npm i
  3. npm i -D [email protected]
  4. npm run build
  5. look at the output file build/lib/commandclass/MultiChannelCC.js

Code
This is the core of the problem

import type { Driver } from "../driver/Driver";
// ...
export class MultiChannelCC extends CommandClass {
	// ...
	public constructor(driver: Driver, options: CommandClassOptions) {
		// ...
	}
}

Expected behavior:
like on the playground link above

Actual behavior:

    MultiChannelCC = __decorate([
        CommandClass_1.commandClass(CommandClasses_1.CommandClasses["Multi Channel"]),
        CommandClass_1.implementedVersion(4),
        __metadata("design:paramtypes", [Driver, Object])
    ], MultiChannelCC);

Notice how the value side of Driver is referenced at runtime, although the import is type-only.

Playground Link: Playground does not allow relative imports

Related Issues: #27519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants