Closed
Description
Bug Report
Related to #37672 and #39337 - seems this bug still happens if class is wrapped by a namespace.
🔎 Search Terms
emitDecoratorMetadata, type-only imports, decorators
🕗 Version & Regression Information
Typescript 4.1.3, Typescript 4.2.0 beta
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about emitDecoratorMetadata and type-only imports
⏯ Playground Link
💻 Code
// @experimentalDecorators
// @emitDecoratorMetadata
// @strict: false
// @filename: services.ts
export namespace Services {
export class Service {}
}
// @filename: index.ts
import type { Services } from './services';
declare const decorator: any;
export class Main {
@decorator()
field: Services.Service;
}
🙁 Actual behavior
Typescript will reference "Services.Service" even though it's not imported (only the type was). This will crash in runtime:
__decorate([
decorator(),
__metadata("design:type", Services.Service)
], Main.prototype, "field", void 0);
🙂 Expected behavior
Should not reference non imported classes:
__decorate([
decorator(),
__metadata("design:type", Object)
], Main.prototype, "field", void 0);