microsoft / microsoft/TypeScript

Auto importing should choose the nearest one where same symbol name is exported from multiple files

Offen
#45,038 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Auto importing should choose the nearest one where same symbol name is exported from multiple files

🔍 Search Terms

auto import
same symbol name

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

💻 Use Cases

When .vscode/settings.json "typescript.preferences.importModuleSpecifier": "shortest",
The following auto importing behavior is very strange:

// src/app1/config.ts
export const LogLevel=1

// src/app1/main.ts
import {LogLevel} from "src/app2/config"
console.log(LogLevel)

// src/app2/config.ts
export const LogLevel=2

// src/app2/main.ts
import {LogLevel} from "src/app1/config"
console.log(LogLevel)

I think it should auto imports the nearest one, but it auto imports the other one.

When .vscode/settings.json "typescript.preferences.importModuleSpecifier": "relative",
The auto importing behavior is OK:

// src/app1/config.ts
export const LogLevel=1

// src/app1/main.ts
import {LogLevel} from "./config"
console.log(LogLevel)

// src/app2/config.ts
export const LogLevel=2

// src/app2/main.ts
import {LogLevel} from "./config"
console.log(LogLevel)

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

Reproduziere die Beispiele mit .vscode/settings.json, wobei importModuleSpecifier auf shortest und relative gesetzt ist. Vergleiche die Auto-Import-Auswahl für die beiden config.ts-Dateien in app1/app2 und verfolge anschließend das TypeScript-Verhalten beim Auto-Import, das die Kandidaten bewertet; als erledigt gilt die Aufgabe, wenn der Modus shortest in beiden Fällen das nächstgelegene exportierte Symbol auswählt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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