interopffirescript

How to represent method calls ReScript 9.1.2


ReScript 9.1.2 made the original @meth semantics inaccessible they said to use @send external instead to represent method calls

My questions are:

can @send external be inside a type? and is this a correct way to use it knowing that it generates the same javascript code?

Using @meth:

@meth
"createElement": string => Web_node.t,

let createElement = typ => document["createElement"](typ 

Using @send external:

@send external
createElement: (t,string) => Web_node.t="createElement"

let createElement = typ => createElement(document, typ)

Solution

  • I don't know what you mean by "inside a type", but yes, that is how you represent a method call. You can verify this by looking at the generated JavaScript. An easy way to do this is by creating an example in the rescript playground, which will show that it generates this:

    function createElement(typ) {
      return document.createElement(typ);
    }
    

    Another handy resource is the rescript bindings cookbook.