Does anyone know if there’s a CLI command to generate an interface file (.resi) from a ReScript source file (.res)? The VS Code plugin supports automatic generation of interface files for the old Reason syntax, but it doesn’t appear to work for ReScript files yet. I think it just calls out to refmt, though. Anyone know the command?
There is the
bsc -i option (print inferred interface). Suppose you have a file
src/Index.res in the project, then it works like this:
bsc -i lib/bs/src/Index.cmi
This prints the interface in ML syntax to standard output. You can also use the
-bs-re-out option to print in RE syntax. I don’t think there’s an option to print ReScript syntax though, but it should be easy to convert using
bsc -format Index.rei >Index.resi.
EDIT: as per the PR linked below by @fham, ‘print inferred interface’ command will print in ReScript syntax by default in an upcoming release.
In the newest release, it should just be
Edit: See https://github.com/rescript-lang/rescript-compiler/issues/5023
Just use it on the source file: https://rescript-lang.org/docs/manual/latest/try#quickly-compile-a-single-file
bsc -i MyFile.res
We’ll extract a dedicated CLI section once the new
rescript binary stabilizes.
It appears this feature will be quite useful for hiding locals for reloading support with create-react-app fast-refresh!
I found adding
-i in your bsconfig.json[“bsc-flags”] will output the types as it builds when using the watcher. Not quite sure the consequences, but this will help me fix a bunch of components quickly then I can remove the flag.
EDIT: I’ve tried
bsc -i src/someComponent.res but it seems to freak out at the sight of JSX and any mention of
React.* any tips for making that work?
Hi, we provided native support for dumping interface on master branch, should be available for public in a couple of weeks
Is the dumping interface able to keep track of the @ annotations when generating an interface? (e.g.
It cannot keep track of ppx transformations as they’re already done, and in general irreversible.
The attribute is preserved so would it be possible to special case it in interface generation?
@react.component changes the original code substantially. It would be possible with some effort to work around that. However, there are plans to simplify the react ppx later on, making this easier.