microsoft / microsoft/TypeScript

[Feature request] sort literals in .d.ts

Aperta
#32,224 9 commenti 15 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Effort: Difficult Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Search Terms

Suggestion

sort string literal in .d.ts

Use Cases

avoid string literal random change order when source code didn't change
and make code history is more easy read

in this issue thread string literal is mean => "a" | "c" | "b"

this not only happen on Record, it has chance happen at all type is auto create by typescript emit with string literal

Examples

"a" | "c" | "b" is create by typesctipt emit and some time will random change order

current .d.ts output

export declare const table_plus: Record<"a" | "c" | "b">
// "a" | "c" | "b" is random change order
in this request

sort ( use simple array.sort() ) it when output emit at .d.ts

export declare const table_plus: Record<"a" | "b" | "c">

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.

Maintainer's note [@sandersn]: To implementers: When you implement this, be sure to sort other literal types too. Consider sorting other things, like symbol, by the order of their string representation.

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 tracciando il percorso di emissione delle dichiarazioni di TypeScript per l'esempio .d.ts, in particolare il modo in cui vengono prodotte le unioni di string literal per i tipi Record. Confronta l'output emesso con l'ordine ordinato richiesto, quindi considera la nota del maintainer sugli altri tipi literal e sui simboli. Il lavoro è terminato quando l'output delle dichiarazioni è deterministico senza modificare il comportamento del JavaScript a runtime.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
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.