microsoft / microsoft/TypeScript
json files should be usable in .d.ts files without breaking things
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
resolveJsonModule import definition
Suggestion
As a .json file is a static resource, it should be able to be referenced in a global.d.ts file for example without that file being automatically treated as a module. The reason for this is that a .json file may be used to simply enforce valid translation keys, and you shouldn't need to suck the whole .json file into the transpilation process to do that.
Use Cases
Example:
import translations from "../assets/translations/en-AU.json"
type $translate = {
instant: (translationKey: keyof typeof translations) => string,
use: Function,
proposedLanguage: Function
}
The downside of the current method again is that the translations file is output in the transpilation process, which is wasteful if the file is large.
What the above code snippet is trying to achieve, should be allowed in a .d.ts file without breaking global declaration functionality.
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. new expression-level syntax)
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 riproducendo l’esempio che coinvolge global.d.ts, un file .d.ts e ../assets/translations/en-AU.json, quindi esamina come vengono attualmente gestiti i file di dichiarazione e gli import JSON. Il lavoro è completato quando l’esempio può fare riferimento al JSON per le chiavi di traduzione senza compromettere le dichiarazioni globali né includere inutilmente il JSON nell’output della transpilation.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100