Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@@js.enum] vs [@js.enum] with polymorphic variant. #109

Closed
hhugo opened this issue Jul 17, 2020 · 0 comments · Fixed by #133
Closed

[@@js.enum] vs [@js.enum] with polymorphic variant. #109

hhugo opened this issue Jul 17, 2020 · 0 comments · Fixed by #133

Comments

@hhugo
Copy link
Contributor

hhugo commented Jul 17, 2020

I'd like to write the following ( [@@js.enum] )

module String_or_number' : sig
  type t =
    [ `string of string [@js.default]
    | `Int of int    [@js.default]
    ]
  [@@js.enum]

  val t_to_js : t -> Ojs.t
  val t_of_js : Ojs.t -> t
end =
  [%js]

It fails with
Error: Sum types without js.* attribute not supported in this context

The way to do it is currently ([@js.enum])

module String_or_number' : sig
  type t =
    [ `string of string [@js.default]
    | `Int of int    [@js.default]
    ]
  [@js.enum]

  val t_to_js : t -> Ojs.t
  val t_of_js : Ojs.t -> t
end =
  [%js]

It would be nice to support the first version.

mlasson added a commit that referenced this issue Feb 3, 2021
@mlasson mlasson linked a pull request Feb 3, 2021 that will close this issue
mlasson added a commit that referenced this issue Feb 5, 2021
* Simplify

* More tests

* Doc fixes

* Typo

* Remove attributes from generated type declarations

* Accept tests after rebasing

* Fix #109

* Fix indentation

* Ok, it is fixed now.

* Fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant