0

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)
glennsl
  • 28,186
  • 12
  • 57
  • 75
Fer iel
  • 23
  • 4

1 Answers1

0

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.

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • inside a type record example: type _xmlhttprequest ={@send external...} yes I am trying the code in the playkground I just wanted to confirm that it is the right way to do it. Thanks for the resource I will check it – Fer iel Aug 11 '22 at 20:55
  • In that sense, no you cannot put it inside a type. `external`s are toplevel definitions, more like function definitions than type definitions, but where the function body is "external". – glennsl Aug 11 '22 at 21:09
  • Thanks for the explanation, appreciate the help – Fer iel Aug 11 '22 at 21:39