microsoft / microsoft/TypeScript
Resolving hoisted `typeRoots` paths
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
TypeScript Version: 3.6.2
Search Terms:
- resolve typeRoots in parent package node_modules
- sharing tsconfig in yarn workspaces
- use hoisted tsconfig in child package
Code
I've set up a Lerna monorepo which uses Yarn Workspaces. Within this monorepo is a config package, which other packages depend on. This config package has @types/node and @types/jest as dependencies.
From sibling packages, the shared config is used like so:
{
"extends": "@project/config/ts.json",
"include": ["src", "tests"],
"compilerOptions": {
"outDir": "lib"
}
}
In the shared config, I point to the appropriate types root:
{
"compilerOptions": {
// ...
"typeRoots": ["node_modules/@types"]
}
}
However, within the shared config package, @types/* have been hoisted from the local node_modules to the monorepo's top-level node_modules. This behavior is usually fine given node's resolution... but it seems the config does not resolve to its parent's node_modules.
Expected behavior:
For the specified type root to resolve to the parent's node_modules
Actual behavior:
Tests fail with messages such as Cannot find name 'describe'. Do you need to install type definitions for a test runner? ...
One workaround:
{
"compilerOptions": {
// ...
"typeRoots": ["../../node_modules/@types"]
}
}
This workaround isn't very clean. Lerna & Yarn definitely pose some complexity for type root resolution. Hopefully resolving parents is considered a worthwhile modification.
Please let me know. Thank you :)
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
Reproduzieren Sie das Setup mit Lerna und Yarn Workspaces mit TypeScript 3.6.2 oder typescript@next unter Verwendung von typeRoots aus der gemeinsamen Konfiguration und der extends-Konfiguration des Schwesterpakets. Beginnen Sie damit, nachzuverfolgen, wie der relative Pfad node_modules/@types aus der gemeinsamen Konfiguration aufgelöst wird, und überprüfen Sie anschließend, dass die geerbten Typdefinitionen des übergeordneten Pakets gefunden werden und die fehlenden describe-Fehler nicht mehr auftreten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100