The following example from the docs get an error stating the arguments a, b will not be used in the function. Also, the logging output is [function anonymout]`
let add = %raw(`
function(a, b) {
console.log("hello from raw JavaScript!");
return a + b
}
`)
Js.log(add(1, 2))
Changing it to any of these yields the same result:
let add: (int, int) => unit = (a: int, b: int) =>
%raw(`
function(a, b) {
console.log("hello from raw add!");
return a + b
}
`)
Js.log(add(1, 2))
let add: (int, int)=>unit => int = (a: int, b: int) =>
%raw(`
function(a, b) {
console.log("hello from raw add!");
return a + b
}
`)
Js.log(add(1, 2))
let x: unit =>int = add(1, 2)
Js.log(x)
[Function (anonymous)]
[Function (anonymous)]
[Function (anonymous)]
What is the proper syntax for creating and calling this function?
It works fine in the playground? You might have some stale compiler version. From the sound of it, you’ve also been accidentally currying some stuff.
Btw, we highly recommend you to keep your JS output tab open so that you can see what you’ve written.
The docs are up to date. As I said, please read them and check the first link you posted, provide the compiler version, and keep the output tab open.
Regarding your error: you’ve used %raw which is not a top-level extension point: Attribute (Decorator) | ReScript Language Manual. Check the output and you’ll see. It doesn’t make sense to have a var statement inside a let statement.