microsoft / microsoft/TypeScript

Improve behavior of typescript.preferences.importModuleSpecifier: non-relative

Aperta
#45,499 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

⭐ Suggestion

Currently, with this setting"typescript.preferences.importModuleSpecifier": "non-relative" VScode goes to the tsconfig file and checks both baseUrl and paths and look for a match.

The situation that I experience is having a few paths in my path property and they sometimes overlap.
Example:

"baseUrl": ".",
    "paths": {
           "*": ["src/main/*"],
          "utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
      },

With this configuration I can import a function from the utilsFunctions folder in one of these 2 options:

  1. import { foo } from "src/main/utils/utilsFunctions/functions.ts
  2. import { foo } from "utilsFunctions/functions.ts

Both of these import statements will work.

But If I add foo in my code without writing the import statement myself, vscode will auto-suggest me to use option no. 1, but In my case, I actually wanted option no.2 (in the above options).

Requested behavior:
When using foo (without it importing it first), VScode should suggest me both options.

My solution, in this case, was to reverse the order of paths like this:

    "paths": {
          "utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
           "*": ["src/main/*"],
      },

🔍 Search Terms

importModuleSpecifier

✅ 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.

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 riproducendo il caso di tsconfig baseUrl e paths sovrapposti, con typescript.preferences.importModuleSpecifier impostato su non-relative. Traccia come viene selezionato il suggerimento di importazione e determina come devono essere presentati entrambi gli specificatori di modulo validi; il lavoro è completato quando vengono suggerite le alternative richieste senza modificare il comportamento di runtime esistente.

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

Valutazione

Stack tecnologico
typescript, vscode
Ambito
developer-experience, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.