microsoft / microsoft/TypeScript
Refactor/codefix: find missing variable in destructured object
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Im Issue werden keine Dateien, Tests oder Einstiegspunkte genannt. Beginne damit, TypeScript language-service codefixes für fehlende Namen und die Behandlung von destructured parameters zu lokalisieren, und vergleiche anschließend das vorgeschlagene Verhalten mit bestehenden auto-import suggestions. Fertig ist es, wenn für eine fehlende Variable vorgeschlagen werden kann, die entsprechende property zum aktuellen destructuring pattern hinzuzufügen, mit Abdeckung für das beschriebene Beispiel.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 28/100