Suggestion: flip the assignment direction of generated enums to save some bits
See original GitHub issueSearch Terms
enum assignment
Suggestion
Flip the assignment order
Use Cases
enums
Examples
enum Action {
foo
bar
baz
thequickbrownfoxjumpsoverthelazydog
}
currently generates:
"use strict";
var Action;
(function (Action) {
Action[Action["foo"] = 0] = "foo";
Action[Action["bar"] = 1] = "bar";
Action[Action["baz"] = 2] = "baz";
Action[Action["thequickbrownfoxjumpsoverthelazydog"] = 3] = "thequickbrownfoxjumpsoverthelazydog";
})(Action || (Action = {}));
Suggesting instead:
"use strict";
var Action;
(function (Action) {
Action[Action[0] = "foo"] = 0;
Action[Action[1] = "bar"] = 1;
Action[Action[2] = "baz"] = 2;
Action[Action[3] = "thequickbrownfoxjumpsoverthelazydog"] = 3;
})(Action || (Action = {}));
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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to easily map c++ enums to strings - Stack Overflow
A brute force solution would be a bunch of functions like this, but I feel that's a bit too C-like. enum MyEnum {VAL1,...
Read more >Handbook - Enums - TypeScript
In this generated code, an enum is compiled into an object that stores both forward ( name -> value ) and reverse (...
Read more >Enumeration types - C# reference - Microsoft Learn
Learn about C# enumeration types that represent a choice or a combination of choices.
Read more >C++ Core Guidelines - GitHub Pages
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++.
Read more >gcc(1) - Linux manual page - man7.org
If you don't use those parts of the language, you can save some space by using ... the temporary array created for the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MarkKahn depends on how creative people get 😃
Yeah, ok… nobody would do this, but you never know.
Flipping assignment order leads to incorrect behavior.
Duplicate of #29838 and #19848