Print TypeScript for a module under the experimental -bs-emit-ts flag
Why
A feasibility study for checking ReScript output with TScert, which reads TypeScript whose top-level functions annotate their parameters and result. The flag writes .res.ts (.mts for .mjs) in place of the JavaScript output, annotates each top-level function from the typed tree, and puts the module's type declarations at the top through genType's translation. The annotations are keyed by Ident.t (name and stamp), so one reaches the output only when the J IR prints the identifier the typed tree bound; RESCRIPT_EMIT_TS_DEBUG=1 reports, per printed top-level function, whether its stamp and its parameters' stamps are the typed tree's.
modifiedJS top-level functions under -bs-emit-ts
type point = {x: int, y: int, label: string}let moveX = (p: point, dx: int) => {...p, x: p.x + dx}
js
Review
- Do the stamps survive to the printer? For every binding
let f = (…) => …at the top level or in a nested module, uncurried, inlined into its callers, private or exported, the printed function and each of its parameters carry the typed tree's stamp. A function the optimizer synthesizes, such aslet partial = curried(1), has fresh parameters and is printed unannotated.