microsoft / microsoft/TypeScript

Intellisense import suggestions - search index files only

Aperta
#38,166 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Hi guys, in large codebases I often encounter following issue:

I work with React/TypeScript combo. If I export something from a file, it's visible to the entire project and Intellisense auto-import feature suggests me all functions/classes/... exported. It's overwhelming to list through all exports, especially in large projects, where different entities can have the same name. I would love to create some sort of hierarchy with use of index files. Auto-import would implicitly "see" only exports within the same folder or siblings of current folder (recursively) if they have exports declared in index file.

Example:

/src
   /module-alpha
      /components
         Alpha.tsx
         List.tsx
         Detail.tsx
         index.ts --> export {default} from './Alpha.tsx'
      /model
         utils.ts
         index.ts --> export * as Utils from './utils'
      ModuleAlpha.tsx
      index.ts --> export {default} from './ModuleAlpha.tsx'
   /module-beta
      /components
         Beta.tsx
         List.tsx
         Detail.tsx
         index.ts --> export {default} from './Beta.tsx'
      /model
         utils.ts
         index.ts --> export * as Utils from './utils'     
      ModuleBeta.tsx
      index.ts --> export {default} from './ModuleBeta.tsx'

If I am in file /src/module-alpha/components/Alpha.tsx and I type Detail, I want the auto-import to suggest me just Detail within the current folder. In this context I would be able to "see":

  • List and Detail from current folder
  • Utils from /model within this module
  • ModuleAlpha
  • ModuleBeta

In other words - folder will behave like a file. If you want the entity to be visible outside the folder, you would have to explicitly define the export in the index file (recursively). I hope that it's clear.

I don't want to change the ES6 module system, and we could still import the entity manually. I just want the intellisense to suggest me only relevant things.

Is this something that can be done?

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 esaminando il comportamento esistente di IntelliSense per gli import automatici e il modo in cui TypeScript risolve le esportazioni dai file index. Confronta i suggerimenti per la struttura descritta di module-alpha e module-beta. Il lavoro è completato quando i suggerimenti sono limitati dalle esportazioni dichiarate ricorsivamente nei file index, mentre gli import manuali rimangono disponibili.

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

Valutazione

Stack tecnologico
react, typescript
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
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.