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
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.
It seems that
bsc -i no longer works:
$ bsc -i src/IDB__Utils.res unknown option: '-i'. Usage: bsc <options> <files> Options are: Options: -w <list> Enable or disable warnings according to <list>: +<spec> enable warnings in <spec> -<spec> disable warnings in <spec> @<spec> enable warnings in <spec> and treat them as errors <spec> can be: <num> a single warning number <num1>..<num2> a range of consecutive warning numbers default setting is +a-4-9-20-40-41-42-50-61-102 -bs-g Debug mode -bs-D Define conditional variable e.g, -D DEBUG=true -e (experimental) set the string to be evaluated in ReScript syntax -bs-uncurry *internal -v Print compiler version and location of standard library and exit -version Print version and exit -warn-help Show description of warning numbers -warn-error <list> Enable or disable error status for warnings according to <list>. See option -w for the syntax of <list>. Default setting is -a+5+6+101+109
Is there a new way to do it?
If you are using VSCode; the
ReScript: Create an interface file for this implementation file command is available via the extension.
I usually don’t use VSCode, but Emacs (old habits die hard); but I can probably open it for this task. It’s not like I need to do it every day.
If that’s exposed through LSP, I could probably make it work with
Maybe you can translate this to lisp: