microsoft / microsoft/TypeScript
disable certain global types for specific files, or specify type roots for specific files.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
This continues some ideas from https://github.com/microsoft/TypeScript/issues/17042, which was closed by @microsoft (for inactivity, I think?).
Search Terms
disable certain global types for specific files, specific type roots for certain files
Suggestion
Ability to specify which @types (or in general, which specified typeRoots) apply to which files in a project.
Use Cases
My project's src folder contains both .ts and .test.ts files, and I'd like an easy way for globals like describe to be defined only for the .test.ts files.
Examples
Not sure, but maybe some sort of new options in tsconfig.json for specifying which types items, lib items, or typeRoots items apply to which files.
This would be a beneficial feature because various editors (VS Code aside) look for a tsconfig.json file at the root of a project, and at the moment the only way to make types work in all files is to just provides all types for all files, which is undesirable because describe is not a function that is available in source files (as an example).
Example configuration: maybe instead of a typeRoots array, it can be an object like:
"typeRoots": {
"./src/**/*.test.ts": ["../path/to/test/types"], // test-only types
"./src/**/*.ts": ["../path/to/@types"] // other types other files
}
Or something. That's just an example to get the idea rolling.
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo l’issue correlata #17042 e gli esempi di tsconfig.json della proposta. Analizza come types, lib e typeRoots vengono attualmente applicati ai file src del progetto, inclusi i file .test.ts. Il lavoro sarà considerato completato quando esisterà un modo documentato e implementato per limitare queste origini dei tipi a file selezionati senza influire sulle configurazioni esistenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100