-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
const enum
Suggestion
So i looked for a way to get all values from const enum without hardcoding them and stumbled upon #21391.
The idea is similar but with one important difference.
Right now when i declare a const enum and use it the compiler replaces the usage with the actual value. The suggestion is allowing the same for values.
So when i write:
const enum Test {
A = 'A',
B = 'B'
}
const test = Test.A;
const test2 = Test.values();
It will compile into:
const test = 'A';
const test2 = ['A', 'B'];
Use Cases
Eliminates the need to either drop const enums or hardcode all the values in an array and remember to add any new enum member.
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.
panchenko, eng-Robert, denisstasyev, alvipeo, Lamby777 and 2 more
Metadata
Metadata
Assignees
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript