Question re constants and enums

I have a couple of enums that I want to use in combination with typechecking because it saves me code for checking valid options. However, when I try to use enums which share some constants I'm running into dead ends:

  • You cannot have the same key in different enums: Redefinition of 'FOO' in '$'. Previous definition at ...
  • You cannot assign enums to consts (see code snippet below) with type checking on gradual (1): Attempting to initialize enum constant 'FooFOO' of enum 'EnumFoo' with an expression.


const FOO = 0;
const BAR = 1;
const BAZ = 2;

// This is not allowed: Duplicate declaration of symbol 'FOO' in module 'globals'.
enum EnumFoo {
  FOO, 
  BAR,
  BAZ,
}

// Working around it:
enum EnumFoo {
  FooFOO = FOO,
  FooBAR = BAR,
  FooBAZ = BAZ,
}

How do people solve this?

Top Replies

All Replies