Js.Dict.values of a Js.Dict.t<array<string>> -> Belt.Array.get not returning option<string>

Hey everyone,

I am trying to get a value from a Js.Dict.t that holds array<string> as its values then grab a value from that array by its index via Belt.Array.get but its being very strange and returning an error that its actually returning option<array<string>> where I would suspect just option<string>

This in theory makes sense, but when I go about accessing the next level of arrays, I end up getting just the first character of each string in the array… I think I might be confused or at least confusing myself with the Js.Dict api :upside_down_face:

Here is a playground as an example:

https://rescript-lang.org/try?code=DYUwLgBA9gDmCWUB2BnAXBAUigdAEXgGMwcwAeAQwCcqKBPMlMK+JAcwD4OIBeLXAsRwAzKlAC2AQRr0AFAG0AugEoAUKtgJkKALQds+IiRThZAIgDK8AF4gzAGgjzL4isGAOIZgDLU2dlQ04RFQ9A0FjUzMAYShgKCpPZwB1AAt4MDtHMwAhYApCAGszQM0Q3X0BIxwTMHMAWQpMljckswAFfKYiTzNkqCgAE1768FbA1VBIN2BeJzLtRXUp6GDkAEYUOZm9HJBgEmlaOhEEgFEC1NkoXm4Ab1UICBWFpHWMV8ZmVk45qDCqkIAG5uACuIAqewOOCO9Bw-jqAAY1E8XmskAAmD7or4sdjcPj-SqGYFgiG7faHGQnBGydYo57gVZaJAAZmxLNxPwJ0ABJJIIOA4MhlJh1Phpgxake-Bw8TYGPMAHl0RB1p5XusKdCVSyJWBkhlUngQMIKKCDuYAHIAekkZmUDIM8sVZl1IQgGI16Ix2pI7uQ+sNYGNpvNlrMtvtjplzqgCuVqtZ3pZrL9OADSCDRpNZotdUjdodagAvtK42xrujNmogA

Thanks!

Dan

You’re probably trying to do this?
You were wrapping it in an extra array.
https://rescript-lang.org/try?code=DYUwLgBA9gDmCWUB2BnAXBAUigdAEXgGMwcwAeAQwCcqKBPMlMK+JAcwD4OIBeLXAsRwAzKlAC2AQRr0AFAG0AUBAiyARAGV4ALxBqANBHmbxFYMAMQ1AGWps9AXQCU+5arUBhKMChVLxgHUAC3gwPUM1ACFgCkIAazVnVxV1AFkKMJYzfzUABRimIks1AKgoABNi1PBspMVnRUVYECQISJBgMEVQSFgEZABGFF43PsRUNwBaDmx8IhIANzMAVxAUKY5pWjoRXwBRWKDZKF5uAG83FR7oOHGBjDHkRmZWTl5oeQAGB0uIa8ekAAmB63J5MFjsbh8KDyAY-FRXcA3fpIADMIJRzwhb2h8kBP1+sx8bEB6gA8qDWgNLACBtN2p0cBSUTh7GAAqEgngQMIKMtOuoAHIAekkaicTkJuGJpLUzPGEEBNMpgPpHRI8uQrPAHLAXJ5fIFahFYolUpwMvJlIgqOVKNRasZmqQ2vZnO5vP5YCFovFkpUAF9JYoiVA2MdKUNJUA

1 Like

So it ended up being my binding output and its why I was getting the correct information when Js.log but strange type errors when trying to actually access the data.

Before:

@module("combinate")
external combinate: Js.Dict.t<array<string>> => array<Js.Dict.t<array<string>>> = "default"

After:

@module("combinate")
external combinate: Js.Dict.t<array<string>> => array<Js.Dict.t<string>> = "default"

Thanks so much for your help!

1 Like