microsoft / microsoft/TypeScript
Refactor/codefix: find missing variable in destructured object
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Search Terms
refactor
codefix
auto import
destructuring
parameter
Suggestion
There is a feature in VSCode today where you can type the name of a function and the editor suggests automatically importing that function, which is very useful.

It would be useful to have a similar feature for finding variables in objects that have been destructured, for example in the props parameters of react functions. It should be possible for typescript to find out that a variable is available in a destructured object in the current closure, for example:

In the above example the first option should suggest to add name to the destructuring of Props in the parameters of the function, since there is a name: string as part of Props.
Use Cases
Using destructuring is very common in for example functional react components. The props object can grow very large and it is annoying and repetitive to type out the name of all the destructured properties.
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Nell’issue non sono indicati file, test o punti di ingresso. Inizia individuando i language-service codefixes di TypeScript per i nomi mancanti e la gestione dei destructured parameters, quindi confronta il comportamento proposto con le auto-import suggestions esistenti. Il lavoro è completato quando una variabile mancante può suggerire di aggiungere la property corrispondente al destructuring pattern corrente, con la copertura dell’esempio descritto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- 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