How do you bind to numeric enum in v11?

In v10, the following variant compiles to values that are all numbers: 1, 2, etc:

    type t =
      | @as(1) Audio
      | @as(2) Cache
      | Config
      | Data

In v11rc2, the variants with explicit as decorators compile to numbers, but those without compile to strings. Is it possible to get the old behavior to bind to numeric enum w/o adding a decorator for every constructor?

No there’s not, you’ll need to add a decorator each constructor if you want to mimic the old behavior.

Oh well. That’s more manual labor than TS, but I guess I can live with it :man_shrugging: Thanks for the reply!

I guess tastes are different. TS enums being numbers by default has always seemed like a design miss to me.

For me it’s not a matter of design preference, it’s a matter of binding to TS APIs with the least efffort :slight_smile:

EDIT: But of course I wouldn’t want the design of the core language features to be maimed by binding requirements

1 Like