microsoft / microsoft/TypeScript
Inconsistencies in ESM-style imports of accessibility-modified properties from CJS-exported classes
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的 CJS-exported class example 开始,追踪当目标是导出的类时,TypeScript 如何处理 NamedImports 与 import-star namespace 的区别。复现可访问性行为的差异,然后验证 named imports 也会强制执行可访问性检查,同时不会暴露 protected 或 private 属性。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100