Guidance for defining module interfaces for React components

I find myself struggling to remember the quirks when defining a module interface for a React component especially when there are optional types. This has become somewhat required when working with a framework like NextJS where hot-reloading breaks if the react component isn’t the the sole export of the module.

My current workflow is to copy the component type signature provided by the tooltip from the rescript extension and then carefully massaging it into a type that works while remember things like: order of the named parameters suddenly becomes important, optional types that would be typed one way in the definition are typed differently in the interface etc.

I’m curious if I’m missing a simpler way to accomplish this.

If you are using VSCode, you can generate it easily from the .res file via the command

ReScript: Create an interface file for this implementation file

You can also click on the icon with the two arrows

if there is no .resi yet, it will be generated for you.

Note that there is also the rescript dump command in the compiler, but it does not really work with modules that contain React components.

1 Like

Nothing concrete planned yet, but it’s definitively on our radar to improve the editor tooling around working with interface files/interfaces in general. Lots to be done, and some fairly low hanging fruit.

Slightly off topic, but here’s an old experiment we did in the editor tooling that’s a bit related:


You all are my saviors

1 Like