How to bind variadic param when the other params are different type?

hello i am new to rescript, and when i want to bind some functions from JavaScript or typescript, there are some parameters with different types in front of the last parameters which are variadic arguments ( aka Rest parameters in js and ts). I wonder know If there any way to bind that and how if yes?

Can you show an example?

For example there is a function in my project with typescript we wrote before,it accept a config and some part of full route, and then generate full routes according to the config, and it’s signature showed as below:

function defineRoutes(config:Config,record: AppRouteRecordRaw): AppRouteRecordRaw[];

function defineRoutes(config:Config, records: AppRouteRecordRaw[]): AppRouteRecordRaw[];

function defineRoutes(config:Config,...otherRecords: AppRouteRecordRaw[]): AppRouteRecordRaw[];
function defineRoutes(

  config: Config,

  record: AppRouteRecordRaw | AppRouteRecordRaw[],

  ...otherRecords: AppRouteRecordRaw[]

): AppRouteRecordRaw[];

The best way is to define multiple bindings for the same function that take the different arguments

external defineRoute: (config, route) => array<route> = "defineRoute"
external defineRoutes: (config, array<route>) => array<route> = "defineRoute"

And then the actual variadic one doesn’t really matter because it’s the same as passing an array

If you look at the Belt bindings, you can see them do the same thing foten with concat() and concatMany()

Belt.Array | ReScript API (rescript-lang.org)

1 Like

Thank you very much this really helped me!

1 Like

sorry but, If there’s only one variadic arguments, what should I do to bind it? I still don’t understand

May I ask why you still want to map to this function when you have a version that already accepts records: AppRouteRecordRaw[]? The varargs variation of the same function looks like a less reliable version of the same thing.

Usually when mapping to variadic argument lists, we’d literally just create 5-6 different bindings that each accept a fixed set of parameters. Kinda like useEffect in the React bindings: useEffect Hook | React