The generated typedefs are almost perfect here, but notice that the generated type Node_t has a property kind of type kind but there is no generated type kind, it’s called Node_kind (and same thing with compositeFactory). Am I doing something wrong here? Or is this perhaps a genType bug?
Are you getting any warnings? This issue suggests that type rec isn’t very well supported due to inherent complexities. But if that’s not related then I think logging a bug there is the next step.
I think it’s actually a bug to do with module scope. I just found that if I move my Node module code out into its own file named Node.res, genType produces well-formed typescript output.
Interestingly, doing so raises a different problem. Previously, genType was generating types with names like Node_t, now it’s just generating types named t. For my end users, I think it would be nice to just rename that type to just Node, which I tried doing via
@genType.as("Node")
type rec t = {
kind: kind,
props: props,
children: array<t>,
}
and kind =
| Primitive(string)
| Composite(compositeFactory)
and compositeFactory = (renderContext, props, array<t>) => t
This works, but the typescript produced is
export declare type t = {
readonly kind: kind;
readonly props: props;
readonly children: t[];
};
export declare type Node = t;
All of my ReScript functions which deal with this type t present their types as t rather than as Node, so any end-user’s IDE intellisense will speak in “t” rather than in type “Node”. Is there a way around that with genType?
Obviously I could literally rename this type in my Rescript, but that seems to break with idiomatic ReScript