microsoft / microsoft/TypeScript
Add option to include default typeRoots when overriding typeRoots
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
Search Terms
default typeRoots
Suggestion
By default, when typeRoots is unspecified, TypeScript looks for node_modules/@types in the project's directory and all ancestor directories, similar to Node's module resolution algorithm. This is covered in the tsconfig.json docs and is implemented here.
When specifying typeRoots in tsconfig.json, this overrides the default typeRoots entirely. You can include "node_modules/@types" in your typeRoots array, but that does not include ancestor directories.
This is a feature request to provide a way, such as a new option, to include the default type roots in addition to the overridden values.
Use Cases
The primary use case is within a repository using Yarn workspaces. Yarn hoists npm packages to the workspace root. This means you can end up with a directory hierarchy like this:
.
├── node_modules
│ └── @types
│ └── dependency
└── packages
└── example
├── example.ts
├── package.json
└── tsconfig.json
If tsconfig.json wants to include node_modules/@types in the workspace root (in addition to other type declaration directories specified in typeRoots), it needs to look like this:
{
"compilerOptions": {
"typeRoots": ["../../node_modules/@types", ...]
}
}
Examples
This feature request is a quality-of-life improvement to instead allow for:
{
"compilerOptions": {
"typeRoots": [...],
"includeDefaultTypeRoots": true
}
}
The default value of this option would be false and would not be a breaking change.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接行附近的 src/compiler/moduleNameResolver.ts 开始,查看描述默认 typeRoots 解析的 tsconfig.json 文档。定义 opt-in 设置如何将显式列出的根目录与祖先目录中的 node_modules/@types 目录结合起来,然后为 workspace 层次结构添加覆盖,并确认默认行为保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- node.js, typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100