microsoft / microsoft/TypeScript

Configurable import suggestions to override global types

Offen
#31,199 1 Kommentar 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: LS: Quick Fixes Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

Suggestion

In our code base we have a module export called Option which we use very often.

However, if we try to reference Option in a module where it's not currently imported, we will not get import suggestions/fixes for this.

This is because there is already a (different) global type of the same name, provided by the dom lib types.

I would like to be able to configure TypeScript and/or VS Code so that I do have import suggestions for Option.

Suggestion: any time a module references a global value, and the project has a module export of the same name, provide an import suggestion for that.

Potential caveat of this suggestion: what happens when you select "add all missing imports"? Ideally I would want it to import my Option, but what if I intentionally wanted to use the global version instead?

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

Beginne damit, das angeforderte Verhalten von TypeScript- und/oder VS Code-Importvorschlägen für einen Modul-Export zu überprüfen, der denselben Namen wie ein globaler DOM-Typ hat. Lege fest, wie explizite Vorschläge und „alle fehlenden Importe hinzufügen“ zwischen dem Modul-Export und der globalen Version wählen sollen. Als erledigt gilt, wenn das Verhalten konfigurierbar ist und der beabsichtigte Anwendungsfall für die globale Verwendung weiterhin klar bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
developer-experience, tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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