Add option to include default typeRoots when overriding typeRoots
See original GitHub issueSearch 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 Analytics
- State:
- Created 4 years ago
- Reactions:189
- Comments:21
Top GitHub Comments
I have a fix for this on my fork, but I cannot PR it due to this issue not being on the backlog: https://github.com/jonrimmer/TypeScript/tree/include-default-type-roots-option
@RyanCavanaugh What feedback are you waiting for on this issue?
Can you please stop typing no value comments like “+1”? It certainly doesn’t help the development process of this issue and you’re sending useless notifications, emails to people who subscribed to this thread and waiting actual feedback.
Use 👍🏻 reaction instead.