DEV Community

Discussion on: TypeScript Enums: 5 Real-World Use Cases

Collapse
 
mrdulin profile image
official_dulin • Edited

The initializers here are not necessary. We could leave off the initializers entirely.

enum Movement {
  Up,
  Down,
  Left,
  Right
}
Enter fullscreen mode Exit fullscreen mode

Here, Up would have the value 0, Down would have 1, etc. This auto-incrementing behavior is useful for cases where we might not care about the member values themselves, but do care that each value is distinct from other values in the same enum.

But of course, you can still use String enums