100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Rescript

By the ReScript core team

AdvancedLanguage12.3K learners

ReScript is a strongly and soundly typed programming language, evolved from the BuckleScript/ReasonML lineage, that compiles to clean, human-readable, and performant JavaScript, designed specifically for building reliable web applications…

Definition

ReScript is a strongly and soundly typed programming language, evolved from the BuckleScript/ReasonML lineage, that compiles to clean, human-readable, and performant JavaScript, designed specifically for building reliable web applications with fast build times and seamless JavaScript interoperability.

Overview

ReScript began life as BuckleScript, an OCaml-to-JavaScript compiler created to give ReasonML syntax a JavaScript compilation target. As the project matured, its maintainers repositioned it away from being 'OCaml for the web' toward being its own language with a curated, web-focused feature set, culminating in a rename to ReScript in 2020. This shift deliberately narrowed scope compared to full OCaml or Reason: ReScript intentionally omits or restricts certain OCaml features (such as unrestricted mutability, exceptions as control flow, and some advanced module system features) in favor of a smaller, more predictable core language optimized for readability, fast compilation, and straightforward interop with existing JavaScript and TypeScript code. The ReScript compiler is written for speed, often compiling projects in a fraction of the time TypeScript's compiler takes, and it generates output JavaScript that closely mirrors the source, making generated code easy to read, debug in browser dev tools, and gradually adopt inside existing JavaScript codebases. Its type system, inherited from OCaml's Hindley-Milner foundations, provides sound static typing with no `any` escape hatch, meaning a ReScript program that compiles is guaranteed to be free of type errors, an assurance TypeScript's structurally optional typing cannot make. ReScript ships with tight bindings for popular JavaScript ecosystems, notably React (via `rescript-react`), and provides variant types, pattern matching, and an immutable-by-default data model, letting teams write functional-style code while still shipping ordinary, framework-compatible JavaScript. It appeals to teams wanting stronger compile-time guarantees than TypeScript without needing OCaml's full generality, though it requires learning a distinct syntax and involves smaller community and library ecosystems than TypeScript.

Key Features

  • Sound, complete static type system with no 'any' escape hatch
  • Extremely fast compiler, often compiling far faster than the TypeScript compiler
  • Compiles to clean, human-readable JavaScript that mirrors the source
  • Deliberately curated language subset focused on web development reliability
  • First-class variant types and exhaustive pattern matching
  • Immutable-by-default data structures with explicit mutability opt-in
  • Strong React integration via dedicated bindings
  • Straightforward interop layer for consuming existing JavaScript/TypeScript packages

Use Cases

Building type-safe React web applications with guaranteed absence of type errors
Incrementally adopting stronger typing inside an existing JavaScript codebase
Teams prioritizing fast build times on large front-end codebases
Replacing PropTypes or loosely typed JavaScript with compiler-verified components
Functional-programming-oriented front-end teams wanting a gentler syntax than OCaml
Library authors wanting to ship both native OCaml and browser JavaScript targets

Alternatives

TypeScript · MicrosoftReasonMLPureScriptElm

History

ReScript was announced on July 1, 2020, as a rebranding and consolidation of the BuckleScript compiler and the Reason syntax into a single, vertically integrated language focused on JavaScript developers. Technically it descends from OCaml: BuckleScript was a fork of the OCaml compiler that emitted JavaScript, and ReScript cleaned up and unified that stack — syntax, tooling, and documentation — under one banner to reduce the learning overhead that had come from juggling OCaml, Reason, and BuckleScript concepts separately. The result is a statically typed language with sound type inference that compiles to fast, readable JavaScript while preserving backward compatibility with existing Reason and OCaml code during the transition.

Frequently Asked Questions