microsoft / microsoft/TypeScript
Preserve radix when pretty-printing numeric literal types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing TypeScript's pretty-printing path for numeric literal types and the handling of auto-incremented enum members; the issue does not name specific files or tests. Done means editor hovers and other pretty-printed output preserve explicitly written binary, octal, or hexadecimal radices, including the illustrated enum case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100