ocsigen / ts2ocaml

Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1.3.0: `enum`s without explicit value are merged

zbaylin opened this issue · comments

I have a simple enum definition like this:

enum Example {
  Foo,
  Bar,
  Baz
}

The Typescript compiler automatically assigns Foo = 0, Bar = 1, and Baz = 2. In v1.2.0, this was generated correctly, i.e.

type t = [
  `Foo
  | `Bar
  | `Baz
]

However, in 1.3.0 (most likely due to the enum merging changes), this becomes one variant:

type t = [ `Foo_Bar_Baz ]

If I modify Example like so:

enum Example {
  Foo = 0,
  Bar = 1,
  Baz = 2
}

The variant is correctly generated again:

type t = [`Bar[@js 1] | `Baz[@js 2] | `Foo[@js 0]]
type t = [ `Foo | `Bar | `Baz ] [@js.enum]

is the same as

type t = [ `Foo[@js "Foo"] | `Bar[@js "Bar"] | `Baz[@js "Baz"] ] [@js.enum]

so it actually had not been working correctly before.

This is now fixed in the latest version 1.3.1.