microsoft / microsoft/TypeScript

Preserve radix when pretty-printing numeric literal types

Aperta
#45,550 7 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Domain: Declaration Emit Domain: LS: Type Display Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

🔍 Search Terms

numeric literal radix, non-decimal numeric literal types

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

If a numeric literal type was defined explicitly with a non-decimal literal, it should be displayed as such in editor hovers and other places where it is pretty-printed.

📃 Motivating Example

Often, non-decimal literals are more-or-less self-documenting in a context:

declare const MASK: 0b1011; // it is obvious which bits are set
// vs
declare const MASK: 11; // wat?
declare const PERMISSIONS: 0o777; // unix file system permissions
// vs
declare const PERMISSIONS: 511; // wat?
declare const ARGB: 0x00ffff00; // yellow pixel color
// vs
declare const ARGB: 16776960; // wat?
declare const ASCII_CODE: 0x1b; // ASCII code for backspace
// vs
declare const ASCII_CODE: 27; // wat?

Ideally, the radix should carry over to the "autoincremented" enum members:

enum AsciiLetters {
  A = 0x61, B, C, D, E, F,  /* ... */, Z,
}
// AsciiLetters.E: 0x65

💻 Use Cases

Bit masks. Unix file system permissions. RGB colors. Hexadecimal ASCII/Unicode code points.

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 pretty-printing di TypeScript per i tipi letterali numerici e la gestione dei membri di enum autoincrementati; l'issue non indica file o test specifici. Il lavoro è completato quando gli hover dell'editor e gli altri output con pretty-printing preservano le basi binarie, ottali o esadecimali scritte esplicitamente, incluso il caso di enum illustrato.

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.