Introduction
ReScript is a compiled language with an ML-family type system that produces clean, performant JavaScript. It compiles an entire project in under a second, provides 100% type coverage with zero runtime overhead, and generates output readable enough to commit alongside source files. It evolved from BuckleScript and Reason to focus on JavaScript-first ergonomics.
What ReScript Does
- Compiles to human-readable JavaScript with near-instant build times
- Provides a sound type system with full inference, eliminating the need for type annotations in most code
- Supports pattern matching, algebraic data types, and labeled arguments
- Generates zero-cost JavaScript interop bindings through an external declaration system
- Integrates with React through first-class JSX syntax and dedicated React bindings
Architecture Overview
The ReScript compiler is written in OCaml and transforms ReScript source into JavaScript in a single fast pass. Type checking and code generation happen together, producing one .js file per .res source file. The compiler resolves dependencies via a bsconfig.json (or rescript.json) file, builds the dependency graph, and compiles only changed files for incremental rebuilds. No intermediate representations are emitted to disk.
Self-Hosting & Configuration
- Install per project:
npm install rescriptand add arescript.jsonconfiguration file - Configure source directories, dependencies, and output format (CommonJS or ES modules) in
rescript.json - Use
npx rescript buildfor one-shot compilation ornpx rescript build -wfor watch mode - Add
@rescript/reactfor React bindings with JSX support - Set up editor support via the rescript-vscode extension for autocompletion and inline errors
Key Features
- Sub-second compilation for entire projects with incremental rebuilds
- Sound type system with no any types, no null/undefined surprises, and exhaustive pattern matching
- First-class JSX support designed specifically for React development
- Zero-cost JS interop through external bindings that produce no wrapper code
- Variants and pattern matching replace unions and switch statements with compile-time safety
Comparison with Similar Tools
- TypeScript — Gradual typing layered on JS; ReScript offers sound types with faster compilation but a different syntax
- PureScript — Richer type system (type classes, higher-kinded types); ReScript prioritizes compilation speed and JS output readability
- Elm — Focused on web UIs with a curated ecosystem; ReScript provides more flexibility and direct JS interop
- Reason — ReScript's predecessor with OCaml compatibility; ReScript dropped OCaml syntax for a JS-friendly experience
- Flow — Facebook's type checker for JS; ReScript is a separate language with its own compiler and guarantees
FAQ
Q: Can ReScript use npm packages? A: Yes. Write external bindings that declare the types of JS functions you want to call. The community maintains bindings for popular libraries, and the compiler generates direct calls with no wrapper overhead.
Q: Is ReScript the same as Reason? A: ReScript evolved from the BuckleScript compiler which supported Reason syntax. ReScript now uses its own syntax optimized for JavaScript developers, while Reason continues as a separate project targeting OCaml.
Q: Does ReScript support React? A: Yes. ReScript has first-class JSX syntax and official React bindings via @rescript/react, supporting hooks, components, and the full React API with type safety.
Q: How fast is the compiler? A: ReScript compiles most projects in under one second. Incremental rebuilds on file changes typically complete in milliseconds, making the feedback loop faster than most JavaScript build tools.