microsoft / microsoft/TypeScript

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

Aperta
#45,038 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

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)

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

Riproduci gli esempi usando .vscode/settings.json con importModuleSpecifier impostato su shortest e relative. Confronta le scelte di importazione automatica per i due file config.ts di app1/app2, quindi analizza il comportamento di importazione automatica di TypeScript che assegna un ordine ai candidati; il lavoro è completato quando la modalità shortest seleziona il simbolo esportato più vicino in entrambi i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.