Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Need help with binding to a function with a complex type

$
0
0

Right, I missed the fact that you need only the keys for the input, but in the result you need the values.

So it’s

type parameterTypeKeys =
  | @as("string") String
  | @as("number") Number
  | @as("boolean") Boolean

@unboxed
type parameterType =
  | String(string)
  | Number(float)
  | Boolean(bool)

Modeled the keys as a separate type now as there is no keyOf in ReScript.
And the parameterType is indeed as you suggested in the last example. We can ensure the wrapper is optimized away in the resulting JS code with @unboxed.

Updated example: ReScript Playground


Viewing all articles
Browse latest Browse all 2592

Trending Articles