Closed
Description
In JavaScript, constructors can also have a rest parameter, and thus can be variadic.
'use strict';
class Foo {
constructor(...names) {
this.names = names;
}
}
let foo = new Foo("bar", "baz");
console.log(foo.names);
Currently, ReScript can't easily bind to these variadic constructors because @new @variadic
is not supported:
type foo
@get external names: foo => array<string> = "names"
@new @variadic external makeFoo : array<string> => foo = "Foo"
// ^ Conflicting FFI attributes found: Attribute found that conflicts with %@new
let foo = makeFoo(["bar", "baz"])
Js.log(foo->names)
As there is no easy workaround to this (especially when the class is imported), I believe @new @variadic
should be supported.
The relevant code is here: https://github.com/rescript-lang/rescript-compiler/blob/4419af7d822c7c9dffe21532624810985915908b/jscomp/frontend/ast_external_process.ml#L792-L811
Metadata
Metadata
Assignees
Labels
No labels