Why do `.resi` and `.res` files require defining records twice (once in each file)?

I tried using a .resi file to help hide an external I didn’t want any code to have access to, but I personally found it annoying having to copy-and-paste the same type definition for a record in both the .resi and .res file.

The docs and compiler didn’t suggest a way to define the record once in the .resi file and then access it in the .res file. Am I missing something? And if not, what’s the design thinking about having to repeat the record definition?

there’s a solution to this:

Overall it can feel like maintaining both .res and .resi files is cumbersome and implies repeating yourself but in a real world use case, it’s really great, you can immediately see just looking at the modified files in a PR if your API changed or if it’s just internal, etc, it allows to hide internal types and functions, it’s pretty cool.


Thanks for the answer! In the end I went with %%private since I was only trying to hide a single function from the file.

private by defaut and a “pub” keyword would be such an improvement :face_holding_back_tears:


I agree that a pub keyword would help make JS devs feel more at home.

Why pub and not just export ?


pub feels more at home with the let binding, and exists in other ML family languages like Rust: Visibility and privacy - The Rust Reference

export let foo = "bar"

pub let foo = "bar"

And we’re not really exporting from a JS file sense, we’re marking something as public in our module, which I think is a distinction worth making.


I like pub myself, but since rescript targets javascript ecosystem I think the choice should be for export

1 Like