ReScript & React Form Event: Type Extension?

Hi all! ReScript beginner here.

I am working on a set of ReScript bindings for the Shoelace React library. Many components emit events specific to the nature of that component: for instance, the Select component will trigger onSlChange, onSlFocus, etc.

For the most part, the events emitted appear to be simple ReactEvent types. However, other components’ custom events have custom keys. The Menu’s onSlSelect contains an event detail { item: SlMenuItem[] }, and the Tree’s onSlSelectionChange contains an event detail { selection: SlTreeItem[] }.

As such, I would like to figure out how to extend the ReactEvent.Form.t type in these specific instances, as one could do with, for instance, Typescript’s & operator ( type1 & { foo: string } ).

I did attempt a spread…

type selectionEvent = {
    ...ReactEvent.Form.t,
    detail: detailType
}

… but it appears that ReactEvent.Form.t is a record and therefore cannot be spread in the current stable ReScript version.

Is there something I am overlooking here?

Really appreciate your help on this! Thanks!

1 Like

But you will be able to extend records (same syntax) in the next rescript version (currently in beta). I don’t know when, but i think the stable version will be released soon.

2 Likes