How do I use the stdlib Dom type?

I currently have this binding.

external requestAnimationFrame: (() => ()) => () = "requestAnimationFrame"

But then I realized that there are some Dom types in the standard library and I see the type window there. Dom | ReScript API

How do I use that type in my binding?

I think these type definitions exist so that libraries can all rely on the same specific type definition, which helps with cross compatibility.

If I was doing a simple binding for RAF I would use the method you have above, but if you’d like to use the type definition you’d need a (1) getter for window and (2) to specify it as a property of window

external window: Dom.window = "window"

@send external requestAnimationFrame: (Dom.window, (unit => unit)) => unit = "requestAnimationFrame"

window->requestAnimationFrame(() => { })
1 Like

Thank you. Another question. I tried to use the Dom.window but my compiler complains that it can’t find the value Dom.window. I am using ReScript 11 rc-4

If you want to use web-apis, install rescript-webapi or at least use their repo as a reference to copy the bindings you need. The value binding for window looks like this:

@val external window: Dom.window = "window"

and can be found here.