How to ues rescript to describes Union Type objects from js/ts

Is it possible to describe an object of type Record<string, string | number | boolean > from the js/ts library with the rescript type.
I can’t predict the key for that input so I should use Js.Dict.t, but I can’t think of a suitable 'a to describe all the possibilities. The first step in rescript for this input would be a check function to verify that this input type meets expectations. For the data after this step of checking and conversion I know how to use the rescript type description
If an accurate description is not possible, what are the best practices for such inputs?

1 Like

Yes, in ReScript v11 this is easy with untagged variants:
https://rescript-lang.org/try?version=v11.0.0-rc.3&code=PTAEoJQUwYwewE4BMA8BnALgglgOwOYA0omOBoAPqLgK4C2ARlApaA3HADZQCGuoAPgBQQgAI1c7AB5QkQjAE8ADlFDxcGKBrSgAvKADKWPPgAUpEwEpWAOXpMEpgGac4PDNaqieaU1hpQ1gAqCAGs3r5OPJxogaAAYtGxIooqoHQKACLYMBh6oABSaAB02bnFGCjqmtrCQtx5GWUYAFzpWTl5+kWlncVQdEqKppYiTZ0AtAI9zcWxGKYARGhwdFAA0lAKi8QhAaPjuVMzffNLK2sA8hgAFsyb28R2jMymAIwADB-FlpZAA

The playground doesn’t have rc.4 yet so I added | as(true) True | @as(false) False to handle booleans, but with rc.4 you’ll be able to simply do Boolean(bool).

6 Likes