Hello,
I wanted to write bindings for react-spring library. I found this thread but I stuck miserably with Rescript basic syntax.
I took the solution, rewrote it to newer bindings syntax. I found what @deriving(abstract)
means in Rescript documentation but I’m a bit lost about how I should use the type parameter in a module.
It’s here:
module Props = {
type t<'a> = Js.t<'a>;
external fromStyle: ReactDOM.Style.t => t<'a> = "%identity";
};
/**
The spring itself
*/
@deriving(abstract)
type t<'source, 'target> = {
@optional
config: Config.t,
@optional
from: Props.t<'source>,
@optional @as("to")
toValue: Props.t<'target>,
@module("react-spring/web.cjs")
external useSpring: (unit => t<'from, 'toValue>) => ('props, (. t<'from, 'toValue>) => unit, 'stop) = "useSpring";
I thought it’s clear, but here:
let (props, setProps, stopProps) = useSpring(() => t(~config, ~from={x: 10}, ~toValue={x: 0}, ()))
I have an error because the compiler doesn’t know type {x: 10}
.
If I define type from = {x: int}
it still would be an error because it wants Props.t
instead of from
.
Props module is not module signature and to be honest, I don’t know to specialize it.
I know I refer to react-related thread, but my main goal here is to understand Rescript syntax for declaring more advanced types and bindings.
I hope you can help me