How to set a dynamic value as a Js.t key in ReScript?

390 views Asked by At

Is there a way to set a dynamic value as a Js.t key in ReScript?

1

There are 1 answers

0
glennsl On BEST ANSWER

No it's not. Js.t is a type where all the keys are known at compile time. It's therefore not possible to add or remove keys at runtime. Js.Dict.t is a type that's also represented as a JavaScript object and which allows keys to be added or removed at runtime. The trade-off here is that all the values need to have the same type, encoded in the type parameter given to Js.Dict.t.