I have been playing around a bit with the new [@bs.deriving abstract]
feature in BuckleScript 3.0.0 and have some feedback:
1.) Thanks, this is great stuff!
2.) For external function declarations, there is [@bs.string]
for turning polymorphic variants into strings. But for fields in a [@bs.deriving abstract]
type, this doesn’t work. It would be great to have a mapping between polymorphic variants and strings here, too.
3.) I would like to be able to customize the name of the generated creation function. Currently, the abstract type and the creation function are generated with the same name (the name of the original type).
E.g.
[@bs.deriving abstract]
type user = {
email: string,
[@bs.as "first_name"] [@bs.optional]
firstName: string,
[@bs.as "last_name"] [@bs.optional]
lastName: string,
};
produces
- an abstract type called
user
and - a function also called
user
with signature(~email: string, ~firstName: string=?, ~lastName: string=?, unit) => user
.
However, I want to put everything into a module User
and call the type “t” and the creation function “make”.
I can do this with the following “workaround”:
module User = {
[@bs.deriving abstract]
type t = {
email: string,
[@bs.as "first_name"] [@bs.optional]
firstName: string,
[@bs.as "last_name"] [@bs.optional]
lastName: string,
};
let make = t;
};
But I would prefer being able to directly specify a different name for the creation function.