News for hackers. Stuff that matters.
Re:Hegel – An advanced static type checker for JavaScript by kamilafsar on Wednesday October 12, 2022 @07:30PM (#33185165)
Interesting, we’re the opposite: use enums where possible. We think it adds more clarity to the reader.

Besides, sometimes number values make more sense then string values. Especially when you want to do bitwise operations, which are not possible on string unions.

Re:Hegel – An advanced static type checker for JavaScript by brundolf on Wednesday October 12, 2022 @08:25PM (#33185630)
That's an interesting point about using number values- I have to say I've never needed to do a bitwise operation in JavaScript, though I know some high-performance projects like physics engines and the TypeScript compiler itself use them

Still, I'd prefer:

  const MyNumericEnum = {
    One: 0b001,
    Two: 0b010,
    Three: 0b100
  } as const

  type MyNumericEnum = typeof MyNumericEnum[keyof typeof MyNumericEnum]
Just for explicitness. But that's my subjective opinion