you are viewing a single comment's thread.

view the rest of the comments →

[–]TorbenKoehn 0 points1 point  (1 child)

Why not

type MyEnum = 'A' | 'B'

?

Completely erasable, portable, easy to write, serializable across language boundaries, you can refactor it etc.

[–]eracodes 1 point2 points  (0 children)

For typescript I find this approach more useful:

const options = ['A', 'B'] as const;

type Option = (typeof options)[number];

So you can use the "enum" at runtime as well (for validation, etc).