microsoft / microsoft/TypeScript
Inconsistencies in ESM-style imports of accessibility-modified properties from CJS-exported classes
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ả
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
Search terms
import AND class AND (protected OR private OR modifier)
Description
Given the following CJS module:
class X {
public static a = 1;
protected static b = 2;
private static c = 3;
}
export = X;
then the behaviour of the static properties when using ESM-style imports is variable. For example,
import { a, b, c } from "module.cjs";
is permitted, but
import * as m from "module.cjs";
const { a, b, c } = m;
is not (m is an alias to the CJS export X, so this counts as a class property access and is subject to accessibility checks).
Protected and private class properties are also offered by tsserver for Intellisense suggestions when using ESM-style imports, but are obviously hidden when offering properties of the "namespace" object created by import * (since it's just an alias to the exported class), and do not appear in its keyof.
(The same would also apply if the CJS export were an instance of a class with accessibility-modified prototype properties, but exporting a class constructor is the more likely scenario encountered in the wild.)
Exposing intended-to-be-hidden properties in this way is almost always going to have been unintentional, and the alternative behaviour is fairly straightforward: add accessibility checks for NamedImports elements when the import target is a CJS export.
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 ví dụ về lớp CJS-exported trong issue và theo dõi cách TypeScript xử lý NamedImports so với một import-star namespace khi đích là một lớp được export. Tái hiện hành vi khác biệt về khả năng truy cập, sau đó xác minh rằng named imports cũng thực thi các kiểm tra khả năng truy cập mà không để lộ các thuộc tính protected hoặc private.
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
- 38/100