microsoft / microsoft/TypeScript

Improve declare module wildcards so that they can match parts of a path more like a glob

Aperta
#38,638 8 commenti 63 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Search Terms

global module match glob path

Suggestion

Improve the declare module wildcards so that they can be used multiple times in a path and they can match multiple parts of it.

Use Cases

In the project I am currently working on we make a distinction between images and icons:

  • icons are usually small in size and used multiple times so we store them as SVG and put them in a SVG sprite with the help of external-svg-sprite-loader.
  • images are usually bigger in size and used only once so we store them as well as SVGs but do not put them in a sprite.

Since SVG imports are not recognized by TypeScript I want to create a global module declaration that targets all icon imports and another that targets all image imports. However, based on the feedback I got in this StackOverflow issue, it doesn't seem to be possible to do this since the support of wildcards in module paths seems to be very limited.

Examples

This is an example of what I would like to be able to do:

declare module '@my/**/icons/**/*.svg' {
    type IconType = { viewBox: string, symbol: string };

    const icon: IconType;
    export = icon;
}

declare module '@my/**/images/**/*.svg' {
    const url: string;
    export = url;
}

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con gli esempi TypeScript declare module dell’issue e analizza come vengono attualmente confrontati i caratteri jolly nei percorsi dei moduli. Confronta il comportamento esistente con i pattern glob ripetuti e composti da più parti richiesti, quindi definisci test che coprano i percorsi delle icone e delle immagini e conferma che entrambe le dichiarazioni corrispondano agli import previsti.

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à
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.