microsoft / microsoft/TypeScript

A way to ignore prefix/suffix in module ID, then resolve the remaining ID as usual

Offen
#37,319 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

Search Terms

wildcard module declarations ignore prefix suffix relative path

Suggestion

import url, { other, exported, values } from 'css:./whatever.css';

TL;DR: I'm looking for a way to say "for all modules starting css:, ignore the css: bit, and resolve the remaining identifier as normal.

As identified by wildcard module declarations, some build tools use prefixes/suffixes to influence how a file is imported.

You can provide types for these:

declare module "css:*" {
  const value: string;
  export default value;
  export const other: string;
  export const exported: string;
  export const values: string;
}

The above allows developers to say "all modules starting css: look like this…".

However, what if the exports from each CSS files differs? This is true for CSS modules, where the class names in a CSS file are 'exported'.

In these cases it's typical to generate a .css.d.ts file alongside your CSS that defines the types. However, if you're using a prefix like css:, TypeScript can't find the location of the .css.d.ts file.

I'm looking for a way to say "for all modules starting css:, ignore the css: bit, and resolve the remaining identifier as normal.

Use Cases

  • Build tools that use prefixes/suffixes to indicate how to process files.
  • Files that may export different things per file (like CSS modules)

Examples

It isn't clear to me if this should be done in tsconfig or in a type definition file.

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

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es wird keine Implementierungsdatei, kein Einstiegspunkt und kein Test genannt. Beginne damit, die verlinkte Dokumentation zu Wildcard-Moduldeklarationen und das CSS-module-Beispiel des Issues zu prüfen. Ermittle anschließend, wie sich das Entfernen des Präfixes auf die normale Modulauflösung auswirken sollte und ob Konfiguration oder Deklarationen angemessen sind. Als erledigt gilt die Aufgabe, wenn ein spezifiziertes Verhalten mit Abdeckung für Präfix-Modulimporte und dateispezifische Exporte vorliegt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.