microsoft / microsoft/TypeScript

Refactor option: Convert Object <-> Map

Aperta
#36,018 0 commenti 2 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
1g 19h
PR unite (30g)
117

Descrizione

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.

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

Esamina l’implementazione del refactoring dell’editor TypeScript e i relativi test, quindi confronta gli esempi richiesti di object e Map. Done dovrebbe fornire una conversione tramite clic destro in entrambe le direzioni, preservando le entry rappresentate e lasciando modificabili i parametri di tipo.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.