How to access window objects in rescript

Hi, I’m a newbie to ReScript.

I want to access an object injected by a library into a window global object, but I don’t know how to do it in script!

For example, I want to access something like below.

// how to do like this in ReScript?
window.someLib.call().

Have a look at the docs.

@val @scope(("window", "someLib"))
external call: unit => unit = "call"

[Playground link]

3 Likes

Worth noting is that you can always reach for %raw and then replace it with a more idiomatic approach at a later stage.

E.g.

let alert = %raw(`
  function(message) {
	window.alert(message)
  }
`)

alert("Hello, World!")
3 Likes