microsoft / microsoft/TypeScript
Missing compiler error (or emit bug) in another isolatedModules + emitDecoratorMetadata use case
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
🔎 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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện được cung cấp trong Playground bằng cách sử dụng type-export.ts và use-decorator-with-type.ts, sau đó kiểm tra đường dẫn của compiler chịu trách nhiệm cho isolatedModules và emitDecoratorMetadata. Tái hiện đầu ra __metadata("design:paramtypes", [Number]) được phát ra và xác định liệu fix hoàn chỉnh nên báo cáo một chẩn đoán isolatedModules hay thay đổi metadata được phát ra, với phạm vi kiểm thử hồi quy cho trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 32/100