-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π Search Terms
"isolatedModules" "emitDecoratorMetadata"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
π» Code
// @isolatedModules
// @experimentalDecorators
// @target: ESNext
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @lib: esnext,decorators.legacy
// @filename: type-export.ts
export type A = 4;
// @filename: use-decorator-with-type.ts
import { type A } from "./type-export.js";
export function Test() {
return undefined as any as ParameterDecorator;
}
export class X {
constructor(@Test() x: A) {}
}π Actual behavior
The key issue here is that the emitted file for use-decorator-with-type.ts looks like this:
/* ... helpers snipped ... */
export function Test() {
return undefined;
}
let X = class X {
constructor(x) { }
};
X = __decorate([
__param(0, Test()),
__metadata("design:paramtypes", [Number])
], X);
export { X };And the problematic line is __metadata("design:paramtypes", [Number]).
Typescript manages to avoid any broken imports and produce working runtime code but the runtime code leaks information about the type of A from the other file by using Number in the metadata. This seems like a clear violation of isolatedModules, but no compiler error is emitted.
π Expected behavior
TS should either emit an isolatedModules-related error or should output something more generic than Number. If the emit is changed, though, I'm not sure what the ecosystem ramifications would be, so probably this should just be an error.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript