Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 12, 2026·3 min de lecture

ReScript — Fast Type-Safe Language for the JavaScript Platform

ReScript is a robustly typed language that compiles to efficient, readable JavaScript with compilation speeds that rival plain JS toolchains, offering an ML-family type system designed for pragmatic web development.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
ReScript
Commande d'installation directe
npx -y tokrepo@latest install e1fb761c-7def-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

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 rescript and add a rescript.json configuration file
  • Configure source directories, dependencies, and output format (CommonJS or ES modules) in rescript.json
  • Use npx rescript build for one-shot compilation or npx rescript build -w for watch mode
  • Add @rescript/react for 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.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires