microsoft / microsoft/TypeScript
Add option to include default typeRoots when overriding typeRoots
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit src/compiler/moduleNameResolver.ts in der Nähe der verlinkten Zeilen und prüfe die tsconfig.json-Dokumentation, die die standardmäßige typeRoots-Auflösung beschreibt. Definiere, wie eine Opt-in-Einstellung explizit aufgeführte Roots mit den node_modules/@types-Verzeichnissen der übergeordneten Verzeichnisse kombiniert, füge dann Abdeckung für die Workspace-Hierarchie hinzu und bestätige, dass das Standardverhalten unverändert bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- node.js, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100