Scripts2026年7月12日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
ReScript
直接安装命令
npx -y tokrepo@latest install e1fb761c-7def-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产