spread operator for enum
See original GitHub issueSearch Terms
- Enum
- Spread operator
Suggestion
I would like to use the spread operator to spread the values (or maybe the keys) of an enum.
Use Cases
I want to use this to check or print available types of enum type.
Examples
enum TestStatus{
PENDING,
ACCEPTED,
WRONG_ANSWER
}
console.log(...TestStatus); // prints: "PENDING" "ACCEPTED" "WRONG_ANSEWR"
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:33
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to merge two enums in TypeScript - Stack Overflow
Using an enum is simple: just access any member as a property off of the enum itself, and declare types using the name...
Read more >How to extend enums in TypeScript - LogRocket Blog
The short answer is no, you can't extend enums because TypeScript offers no language feature to extend them. However, there are workarounds you ......
Read more >Spread Operator - Beginners Guide to TypeScript - Fullstack.io
The spread operator faciliates three common tasks: Copying the elements of one or more arrays into a new array. Copying the properties of...
Read more >What is the enum in JavaScript? - JS Remote jobs
Defining enum via Object.freeze() · value: the actual value of the property. · enumerable: determines whether the property will appear when ...
Read more >Enum With and Without Values - Learn TypeScript - Educative.io
A mixed enum value type is acceptable if every member is defined. For example, you can have one item be an integer and...
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
This can be done right now with
Object.values
:This would be cool, if added anytime soon. As of now the suggestion of @nickbclifford does the job
console.log(...Object.values(Enum))
.