Hi! I’m new to ReScript and am learning by replacing a Js library i’ve written with rescript.
it’s a react component
it uses render props
it takes an array of items in props which can be any shape, the component itself doesn’t care (the array must have items of the same type, but the component doesn’t rely on that type being anything in particular)
I’m having a problem with #3 - Rescript seems to infer array<int> when I expect it to use array<'item>
Thank you! That worked, and switching to a tuple is a great call, thanks.
Another question, what’s the best way to model onEnd? Its a callback passed in by the consumer, and in TS I’d model it as an optional (any) => any. What’s a better way?
In this case, you can use the ignore function to “eat” the output and return unit. I.e., something like
let onEnd = ...
let x = ...
let onEnd = () => ignore(onEnd(x))
This should mean the caller provides a function of type unit => unit, which fit into the type.
My experience is that it is usually better to define the narrowest possible interface and have the caller adapt to it rather than having the callee handle multiple types of different possible inputs, where applicable.