ppx_spice icon indicating copy to clipboard operation
ppx_spice copied to clipboard

Optional type encodes to option<Js.Json.t> instead of Js.Json.t

Open reebalazs opened this issue 1 month ago • 7 comments

I see this on 0.2.2. This has changed recently, breaking my existing code.

@spice
type mystring = option<string>

let encoding = (str): Js.Json.t => {
  str->mystring_encode
}

This code gives an error:

  16 │
  17 │ let encoding = (str): Js.Json.t => {
  18 │   str->mystring_encode
  19 │ }
  20 │

  This has type: option<Js.Json.t>
  But it's expected to have type: Js.Json.t (defined as Js_json.t)

So for some reason the payload type becomes option<Js.Json.t> if the item itself is optional. Shouldn't the encode result always be just Js.Json.t?

At the same time this works, so the problem is only with the first-level option.

@spice
type mystring = {content: option<string>}

let encoding = (str): Js.Json.t => {
  str->mystring_encode
}

I'll test this eventually with the newest code. (I am on 0.2.2 currently because Rescript v11 does not run with 0.2.3.)

reebalazs avatar Jan 12 '25 15:01 reebalazs