Is there any way to prevent transpiling to this function wrapping?

bindings

type t
@module("@fastify/cors") external cors: t => Promise.t<unit> = "default"
@send external register: (t, t => Promise.t<unit>) => unit = "register"

code:

let server = Fastify.make()
Fastify.register(server, Fastify.cors)

.bs.js

import Fastify from "fastify";
import Cors from "@fastify/cors";

var server = Fastify();

server.register(function (prim) {
      return Cors(prim);
    });

This causes errors like

TypeError: Cannot read properties of undefined (reading 'delegator')

If I edit the bs.js file and remove that weird combinator it no longer errors. I haven’t figured it out yet but it might have something to do with reflection using argument counts.

server.register(Cors);
type t
type plugin
@module("@fastify/cors") external cors: plugin = "default"
@send external register: (t, plugin) => unit = "register"
1 Like

Almost worked, but what happened is that there’s also code that isn’t a plugin (both plugins and routes are the same signature)

let routes = async server => {
  server->Fastify.get("/", root)
  server->Fastify.get("/hello", helloThere)
  server->Fastify.postWithValidation("/auth", AuthRoutes.authSchema, AuthRoutes.auth)
  server->Fastify.get("/deauth", AuthRoutes.deauth)
}

Fastify.register(server, routes)

But if I changed

type plugin

to

type plugin = t => promise<unit>

it seems to work in both cases, but I’m not sure if that’s just lucky or not.