Skip to content

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

Closed
@AlCalzone

Description

@AlCalzone

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions