microsoft / microsoft/TypeScript
Non-exported classes in type declaration files leaking value names
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 3.5.2
Search Terms: ambient module declaration export declare class type name
Code
In a file called classes.d.ts:
declare class A {}
export declare class B extends A {}
In a file called test.js:
let a = require('classes').A;
In a file called test.ts:
import { A } from './types/classes';
[NEW] Assumptions:
The following is a list of assumptions I had when originally opening this issue:
- Type Declaration Files work like modules: once you use
importorexport[on a top-level declaration], only explicitlyexported declarations are visible externally. - Type names declared in a Declaration File are always accessible via
importtypes (at least those that are used byexported types.- E.g.
export class B extends Aexports the type namesAandB, even ifAwas not directlyexported.
- E.g.
- Value names declared in a module-style Declaration File (see
#1above) are only accessible if explicitlyexported.
These assumptions are the result of reading the documentation and working with declaration files. Note that the documentation does not mention:
- All declarations in a declaration file are implicitly exported.
- Special [and undocumented?]
export {};syntax causes only explicitlyexported declarations to be available by consumers of the declaration file.
I list them here to provide context for the Expected Behavior section.
Expected behavior:
In both cases , an Error that name 'A' could be found in module 'classes'.
I expect in this case that TypeScript is capable of resolving the following from the declaration file:
In other words, I should be able to use import types to resolve class A, but attempts to use them should fail.
Actual behavior:
No compiler error in either case. TypeScript-powered IDEs (e.g. VSCode) happily show that the full non-exported class A is available.
In short, a non-exported, declared class should resolve in the same way as an interface.
As things stand today, TypeScript erroneously resolves the Value "A".
Playground Link: NA
Related Issues: NA
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 issue 中的 classes.d.ts、test.js 和 test.ts 示例重现该行为,然后跟踪 TypeScript compiler 中声明文件的模块和符号解析。完成标准是:未导出的类 A 不会作为值暴露,同时导出的类 B 所需的类型引用仍能继续解析,并为两个示例提供回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100