To have proper interop with JS, there is a need for binding to tagged template literals. I especially run into this with graphql-ppx because most GraphQL libraries use tagged template literals to represent GraphQL operations and fragments. We found a hacky way to bind to them that involves require and %raw but it’s not ideal.
I think there could be quite nice way to bind to them. The below could be the function signature:
let graphql: (array(string), @variadic array('a)) => 'b
And the following syntax:
would be the same in ReScript and JS. It can even be supported in non-es6 by just calling the function.
The “only” language feature we need is the @variadic annotation in the last argument. Not sure if that is feasible, and it might be only implementable with an external (which would actually be quite ok, because normally we would only use template literals to bind to external libraries).
Perhaps the ... operator can help to spread the arguments. If the function has a variadic annotation ReScript can compile the JS with that operator. The operator can also be used on the function implementation side.
let bla = (first, ...rest) => [first, rest];
bla(1,2,3) // => [1, [2,3]]
bla(1, ...[2,3]) // => [1, [2,3]]