0

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

Siraj Kakeh
  • 741
  • 6
  • 20

1 Answers1

1

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.

glennsl
  • 28,186
  • 12
  • 57
  • 75