microsoft / microsoft/TypeScript

Refactor option: Convert Object <-> Map

Offen
#36,018 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

Refactor Maps to Objects
Refactor Objects to Maps
Convert objects convert maps

Suggestion

I would like to see the ability to right click on a map or object and be able to quickly and easily change the format between an object literal and a Map definition. Would help a lot when prototyping new code.

const o = {
    a: 1,
    b: 2,
};
const o = new Map([
    ["a", 1],
    ["b", 2],
]);

Use Cases

This is great when quickly prototyping new code and quickly typing the kind of object you want. If you decide a Map would be better suited for this use case after typing out an object, then you can easily just right click + refactor to isObject ? "Map" : "Object". At the moment, the easiest way to do this in VSCode that I'm aware of is to multi-cursor all the lines and try to modify the format on each line simultaneously, then edit the first and last lines to start with new Map([ and end with [)
It doesn't need to be SUPER sophisticated. The developer can easily change the Map type parameters, for example. It would just be nice to have a way to quickly convert between the two formats.

Examples

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

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Überprüfe die Implementierung des TypeScript-Editor-Refactorings und die zugehörigen Tests und vergleiche anschließend die angeforderten Beispiele für object und Map. Done sollte eine Konvertierung per Rechtsklick in beide Richtungen ermöglichen, wobei die dargestellten Einträge erhalten bleiben und die Typparameter bearbeitbar bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, 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
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.