explaingit

chenglou/freerange

Analysis updated 2026-05-18

388TypeScriptAudience · developerComplexity · 3/5Setup · easy

TLDR

Freerange is a compile-time TypeScript checker that tracks the possible range of every number in your code to catch bugs like division by zero, NaN, and out-of-bounds array access before runtime.

Mindmap

mindmap
  root((Freerange))
    What it does
      Tracks number ranges
      Catches div by zero
      Catches NaN bugs
      Compile-time checks
    Tech stack
      TypeScript
      Bun
      Node.js
    Features
      Static console.assert
      fr audit command
      No annotations needed
    Use cases
      UI layout safety
      AI agent refactoring
      Build pipeline checks

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Catch division-by-zero and NaN bugs in UI layout math before the app ever runs in a browser.

USE CASE 2

Prove that console.assert conditions in your code can never be false, directly at compile time.

USE CASE 3

Guide an AI coding agent to refactor numeric calculations into a style that's easier to statically verify.

USE CASE 4

Add an extra static-analysis check alongside the regular TypeScript compiler in a build pipeline.

What is it built with?

TypeScriptBunNode.js

How does it compare?

chenglou/freerangetritano/ultraviewerkenkaneki18/cloakbrowser
Stars388388386
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasyeasymoderate
Complexity3/51/53/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Install with bun or npm as a dev dependency, works best on code written in Freerange's supported TypeScript subset.

No license information is stated in the README.

In plain English

Freerange is a command-line tool that analyzes TypeScript code and tracks the possible range of every number in your project, so it can catch bugs like division by zero, NaN values, infinite values, and array indexes that go out of bounds. It does this at compile time, meaning it checks your code before you ever run it in a browser, similar to how the regular TypeScript compiler catches type errors before runtime. Freerange works directly on top of the official TypeScript compiler API rather than being a new language or a fork of TypeScript, so there are no special annotations or library functions to learn. You install it as a dev dependency with a package manager like bun or npm, then run its command, called fr, which prints errors and warnings about your code, or fr audit, which prints a fuller report of each function's assumptions along with suggestions for restructuring code so Freerange can analyze it more effectively. One notable feature is that it gives new meaning to a lesser-known JavaScript function called console.assert. Normally that function only checks conditions while your code is actually running, but Freerange reads certain simple console.assert statements at compile time and proves whether they could ever be false, catching the mistake before the code ships, without needing to start the app. Freerange intentionally supports a specific, well-defined subset of TypeScript rather than every possible pattern the language allows, since some code patterns make this kind of numeric analysis mathematically very hard or even impossible to solve. The README explains this subset in detail and recommends restructuring important numeric calculations into small, named, synchronous functions with clear inputs and outputs, a style similar to functional programming, since that shape is what Freerange can reason about best. The authors note this restructuring is a good task to hand to an AI coding agent, since it is mechanical and Freerange's audit command gives explicit, actionable guidance for what needs to change.

Copy-paste prompts

Prompt 1
Install freerange as a dev dependency in my TypeScript project and run fr to check for numeric bugs.
Prompt 2
Explain how Freerange proves a console.assert statement true or false at compile time.
Prompt 3
Show me how to restructure a numeric calculation so Freerange's static analysis can follow it.
Prompt 4
What TypeScript patterns does Freerange not support, and why do they make analysis harder?
Prompt 5
Run fr --audit on this file and explain the refactor suggestions it gives.

Frequently asked questions

What is freerange?

Freerange is a compile-time TypeScript checker that tracks the possible range of every number in your code to catch bugs like division by zero, NaN, and out-of-bounds array access before runtime.

What language is freerange written in?

Mainly TypeScript. The stack also includes TypeScript, Bun, Node.js.

What license does freerange use?

No license information is stated in the README.

How hard is freerange to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is freerange for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.