microsoft / microsoft/TypeScript
Missing compiler error (or emit bug) in another isolatedModules + emitDecoratorMetadata use case
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
"isolatedModules" "emitDecoratorMetadata"
### 🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
### ⏯ Playground Link
https://www.typescriptlang.org/dev/bug-workbench/?importHelpers=true&experimentalDecorators=true&emitDecoratorMetadata=true&target=99&module=1&isolatedModules=true&noResolve=true&lib=lib.esnext.d.ts%2Clib.decorators.legacy.d.ts&ts=5.3.2#code/PTAEAEEsGcHsBsCGAXApgEwLK3QV3qtAFAgSoAeADqgE6QC2qAdsovACKoDGsNKvxUuFY0A5qmQAuUAFEAygDkKyEmHAVqdRizacefZAOnIauVKrL1IyPb341MExOhSJjp80PiQARtMJMygA06Nx2hjTQAHQEoohcAJ4W4ABmkARMiIzGCdQAtBq8yFHIxIU0yKDIuaigAIKgALygACwA3ETJaRlZqNK40Kh5ofr2eQDu1gAWedXUJcQMlEWgAN5VNfWgAL6gKTSw9KAARFHAc0PlxQBW0McdRFd7uExcyJCwTKAAKoTIABQASjWRFAoBoElwNC+L1CaUC6FAiGgSKYCSRKIACog+Iw0DRbAZeB1tp0nlwkNAUQANEFgnhMaAmXBvXj-cC-JlA0DkaR1YGrUnbIA
### 💻 Code
```ts repro
// @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:
```ts
/* ... 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_
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先使用 type-export.ts 和 use-decorator-with-type.ts 从提供的 Playground 复现开始,然后检查负责 isolatedModules 和 emitDecoratorMetadata 的编译器路径。复现发出的 __metadata(\"design:paramtypes\", [Number]) 输出,并确定完成的 fix 应报告 isolatedModules 诊断,还是应更改发出的元数据,同时为此情况添加回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 32/100