This project tries to setup interaction between the TypeScript and the Reason compiler.
We use genType
to generate TS type declarations from ReScript.
npm install
Native:
opam switch create 4.11.1
opam install base stdio dune ocaml-lsp-server atdgen
npm run re:build && npm run build
Native build:
dune build src/ocaml/read_ast.exe
npm run re:watch
In another:
npm run watch
npm run run src/examples/tree.ts
Run native:
_build/default/src/ocaml/read_ast.exe src/examples/tree.ts.json
The data types and JSON (de-)serializers for asts are generated by atdgen. To re-generate, run:
npm run atd
I have not yet figured how to let this multi-project setup play nicely with Merlin.
If one deletes the .merlin
file at the root, then it works nicely for all the OCaml files.
Otherwise, it will not find the local libraries.
However, the .merlin
file is probably needed to get all features for ReScript files.
genType
only generates.tsx
files (issue). We work around this by setting"jsx": "react"
intsconfig.json
.genType
usesrequire
(issue). This is annoying because it means we cannot use Node's ES6 module mode. Workaround: use theesm
package.- In Node's ES6 mode, file paths need to carry explicit file type suffixes. TS refuses to generate them.
One way to fix it is to use
.js
imports in the original TS file (like so). The other is to updatetsconfig
like so. This problem vanishes as soon as we useesm
. - The paths to the Babel plugins in
src
are set as absolute paths inbabel.config.json
, and need to be adopted to your machine. They should go after all official Babel plugins, in the following order:mybabel
babel-for-to-while
babel-transform-update-expression
babel-transform-object-spread
babel-transform-unary-expression
babel-transform-delete
babel-transform-array-push
babel-transform-property-assignment
babel-rename
babel-hoist-declarations
babel-transform-internals
- The module
simple_fun
needs to be installed locally via opam.