Variables that can't be generalized when writing a dynamic JS function


#1

I’m trying to write some simple code to wrap https://github.com/prismagraphql/prisma-binding, and here’s what I’ve got:

As yo ucan see on line 21, I’m trying to annotation the “query” function, which will dynamically pass the query name, arguments, and selection to the prisma binding. But I’m getting the old compiler error This expression's type contains type variables that can't be generalized.

Any ideas about how to better go about this?


#2

One approach here would be to wrap that function in a Functor, so you could make sure that the user locks down the types (instead of having them be “you can pass in anything”.

so

let module Query = (Config: {type args; type selection;type result}) => {
  
  let run: (string, Js.t(Config.args), Config.selection) => Js.Promise.t(Config.result) =
    fun%raw (queryName, args, selection) => {|
    return conn.query[queryName](args, selection)
  |};

};

#3

That’s a great idea. Thank you!

For simplicity and speed at the moment I actually ended up changing those parameterized types all to Js.Json.t and building them with bs.raw :cowboy_hat_face: :boom: :rescue_worker_helmet: