Every failure lives in the return type. null doesn't exist. State is never mutated behind your back. SAFE-TS checks your whole program in milliseconds—turning the silent bugs coding agents ship into compiler errors with actionable fixes.
Live WebAssembly Checker
Loading the Rust checker (WebAssembly, ~700 kB)…
This is the real Rust checker compiled to WebAssembly. It inspects a single file—imports don't resolve here, so cross-module failure tracking runs through the CLI, CI, or editor LSP.
Why Strictness Works Now
Coding agents write faster than anyone can review, and they reproduce every silent TypeScript trap: swallowed errors, null mixed with undefined, unchecked casts, unvalidated JSON, shared mutable state, and async races. Every one of them looks fine in a diff. On real work projects, SAFE-TS caught around 25 real bugs in each.
What makes strict code tiring for a person costs an agent nothing. Twenty explicit lines instead of three, a Result on every failing call, a reason on every escape hatch: an agent never gets tired of that. What it needs is a fast, precise compiler signal—and because an agent aims at "the checker passes", SAFE-TS puts its effort into deep whole-program static analysis with every escape hatch counted.
tsc --strict still type-checks.node_modules.std helper or pattern replaces it.--baseline locks unsafe() and ignore counts so technical debt only trends down.Core Philosophy
A function that can fail declares it in its return type (Result<T, E>), or throws a tracked PropagateError that something upstream is proven to catch.
Absence is always T | undefined (Option<T>). null is banned so every ?., ??, and optional check speaks a single language.
No mutable module globals. Parameters are read-only unless typed Mut<T> and explicitly lent at the call site with mut(value)—like Rust's &mut.
External JSON, files, and network payloads are validated against your TypeScript types using build-time generated validators and proof brands.
Side-by-Side · Every Example Is a Test
Each pair below runs in cargo test and tsc --strict. Rejected code must trigger the exact rules shown; accepted code produces zero diagnostics. Where the build transform rewrites accepted code, switch to the Compiled tab to inspect the emitted JavaScript.
throw hides the failure from the function signature, so callers only discover it in production.
export function parsePort(text: string): number {
const port = Number(text);
if (!Number.isInteger(port)) throw new Error(`not a port: ${text}`);
return port;
}Named PortError variants live in the return type. q(...) propagates errors like Rust's ? and compiles to a plain early return.
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, q, type Result } from "@evobug_com/safe-ts-std/result";
export type PortError = Enum<{ NotANumber: { text: string }; OutOfRange: { port: number } }>;
const PortError = constructors<PortError>();
function parsePort(text: string): Result<number, PortError> {
const port = Number(text);
if (!Number.isInteger(port)) return err(PortError.NotANumber({ text }));
if (port < 1 || port > 65535) return err(PortError.OutOfRange({ port }));
return port;
}
export function address(host: string, port: string): Result<string, PortError> {
const checked = q(parsePort(port));
return `${host}:${checked}`;
}import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { Err as __qErr } from "@evobug_com/safe-ts-std/result"; import { err, q, type Result } from "@evobug_com/safe-ts-std/result";
export type PortError = Enum<{ NotANumber: { text: string }; OutOfRange: { port: number } }>;
const PortError = constructors<PortError>();
function parsePort(text: string): Result<number, PortError> {
const port = Number(text);
if (!Number.isInteger(port)) return err(({ tag: "NotANumber", text } satisfies PortError as PortError));
if (port < 1 || port > 65535) return err(({ tag: "OutOfRange", port } satisfies PortError as PortError));
return port;
}
export function address(host: string, port: string): Result<string, PortError> {
const __q1 = parsePort(port); if (__q1 instanceof __qErr) return __q1; const checked = __q1;
return `${host}:${checked}`;
}More in the errors guide.
Two spellings for "missing" force every caller to remember whether this API uses null or undefined.
export type User = { readonly name: string; readonly email: string | null };
export function findEmail(user: User): string | null {
return user.email === "" ? null : user.email;
}One spelling—undefined via Option<T>—matching ?., ??, and optional properties everywhere.
import type { Option } from "@evobug_com/safe-ts-std/result";
export type User = { readonly name: string; readonly email: Option<string> };
export function contactLine(user: User): string {
return user.email === undefined ? user.name : `${user.name} <${user.email}>`;
}More in the absence guide.
The caller's cart is mutated in place, and nothing in the signature warns callers about it.
export type Cart = { items: string[]; total: number };
export function addItem(cart: Cart, item: string, price: number): void {
cart.items.push(item);
cart.total += price;
}Return the updated cart—or declare in-place mutation explicitly with Mut<Cart> and lend with mut(cart).
export type Cart = { readonly items: readonly string[]; readonly total: number };
export function addItem(cart: Cart, item: string, price: number): Cart {
return { items: [...cart.items, item], total: cart.total + price };
}More in the state guide.
A switch that compiles today and silently skips the variant someone adds tomorrow.
type Payment = { tag: "Card"; last4: string } | { tag: "Transfer"; iban: string };
export function describe(payment: Payment): string {
let text = "a payment";
switch (payment.tag) {
case "Card":
text = `card ending in ${payment.last4}`;
break;
case "Transfer":
text = `transfer from ${payment.iban}`;
break;
}
return text;
}match(...) requires every variant to be handled and compiles down to a flat switch.
import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
type Payment = Enum<{ Card: { last4: string }; Transfer: { iban: string } }>;
export function describe(payment: Payment): string {
return match(payment, {
Card: ({ last4 }) => `card ending in ${last4}`,
Transfer: ({ iban }) => `transfer from ${iban}`,
});
}import { unreachable as __matchUnreachable } from "@evobug_com/safe-ts-std/enum"; import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
type Payment = Enum<{ Card: { last4: string }; Transfer: { iban: string } }>;
export function describe(payment: Payment): string {
{ const __ms1 = payment; let __mv1: string; switch (__ms1.tag) {
case "Card": { const { last4 } = __ms1; __mv1 = `card ending in ${last4}`; break; }
case "Transfer": { const { iban } = __ms1; __mv1 = `transfer from ${iban}`; break; } default: __mv1 = __matchUnreachable(__ms1); } return __mv1; }
}More in the enums guide.
JSON.parse can throw, and as User blindly trusts whatever shape arrives over the wire.
type User = { readonly id: string; readonly name: string };
export function loadUser(text: string): User {
return JSON.parse(text) as User;
}parseJson<User> validates the payload using a build-time validator generated from User and returns a Result.
import { parseJson, type JsonError } from "@evobug_com/safe-ts-std/json";
import type { Result } from "@evobug_com/safe-ts-std/result";
type User = { readonly id: string; readonly name: string };
export function loadUser(text: string): Result<User, JsonError> {
return parseJson<User>(text);
}import { parseJsonWith as __jsonParse, validateWith as __jsonValidate, jsonFail as __jsonFail, isJsonErr as __jsonIsErr, isJsonObject as __jsonIsObject, type JsonResult as __JsonResult } from "@evobug_com/safe-ts-std/json"; import { parseJson, type JsonError } from "@evobug_com/safe-ts-std/json";
import type { Result } from "@evobug_com/safe-ts-std/result";
type User = { readonly id: string; readonly name: string };
export function loadUser(text: string): Result<User, JsonError> {
return __jsonParse<User>(text, __v0);
}
// ---- generated by safe-ts: JSON validators ----
type __T0 = { "id": string; "name": string; };
function __v0(v: unknown, p: string): __JsonResult<__T0> {
if (!__jsonIsObject(v)) return __jsonFail(p, "object", v);
const __j1 = v["id"];
if (typeof __j1 !== "string") return __jsonFail(p + ".id", "string", __j1);
const __j2 = __j1;
const __j3 = v["name"];
if (typeof __j3 !== "string") return __jsonFail(p + ".name", "string", __j3);
const __j4 = __j3;
const out: { "id": string; "name": string; } = { "id": __j2, "name": __j4 };
return out;
}More in the JSON guide.
The try exits before the promise rejects, so the catch block never runs.
import { PropagateError } from "@evobug_com/safe-ts-std/result";
class Offline extends PropagateError {}
async function upload(file: string): Promise<void> {
if (file === "") throw new Offline("no connection");
}
export function save(file: string): void {
try {
upload(file);
} catch {
console.error("never runs");
}
}Return the failure as a Result inside the promise so save awaits it and handles both outcomes explicitly.
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
type UploadError = Enum<{ Offline: {} }>;
const UploadError = constructors<UploadError>();
async function upload(file: string): Promise<Result<void, UploadError>> {
return file === "" ? err(UploadError.Offline()) : undefined;
}
export async function save(file: string): Promise<string> {
const uploaded = await upload(file);
return isErr(uploaded) ? "offline, will retry" : "saved";
}import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
type UploadError = Enum<{ Offline: {} }>;
const UploadError = constructors<UploadError>();
async function upload(file: string): Promise<Result<void, UploadError>> {
return file === "" ? err(({ tag: "Offline" } satisfies UploadError as UploadError)) : undefined;
}
export async function save(file: string): Promise<string> {
const uploaded = await upload(file);
return isErr(uploaded) ? "offline, will retry" : "saved";
}✅ Also accepted: when Offline aborts the whole job and is caught once at its top boundary, await the PropagateError inside try:
import { PropagateError } from "@evobug_com/safe-ts-std/result";
class Offline extends PropagateError {}
async function upload(file: string): Promise<void> {
if (file === "") throw new Offline("no connection");
}
export async function save(file: string): Promise<string> {
try {
await upload(file);
return "saved";
} catch {
return "offline, will retry";
}
}More in the async guide.
Zero-Friction Integration
safe-ts lsp reports cross-file diagnostics as you type in .ts, .tsx, and .vue, lists every possible failure on hover, and applies one-click quick fixes. Works alongside the oxlint plugin (Editor).
The Vite plugin, Node loader, and Bun preload rewrite q(...), match(...), parseJson<T>(...), and array chains into plain fast JavaScript. Run safe-ts explain to inspect every rewrite.
Checks SFC templates as real code: catches async watcher races, split loading/error refs, prop mutations, missing v-if guards, and XSS sinks.
Checks .tsx components and custom hooks: flags dropped handler Results, racing effects, uncached use() promises, and missing effect cleanup.
Get Started in 60 Seconds
Packages are published on npm under @evobug_com with prebuilt native binaries for Linux (x64, arm64), macOS (x64, arm64), and Windows (x64).
npm install -D @evobug_com/safe-ts-transform @evobug_com/oxlint-plugin-safe-ts oxlint
npm install @evobug_com/safe-ts-std{ "extends": ["./node_modules/@evobug_com/oxlint-plugin-safe-ts/recommended.json"] }import { safeTs } from "@evobug_com/safe-ts-transform";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [safeTs()] });node --import @evobug_com/safe-ts-transform/register main.tspreload = ["@evobug_com/safe-ts-transform/bun"]
[test]
preload = ["@evobug_com/safe-ts-transform/bun"]npx @evobug_com/safe-ts-skillgit clone https://git.evobug.com/Evobug/Safe-Ts.git
cd Safe-Ts
npm install
npm run build # the Rust checker and its Node addon
npm run check # check the demo app, which has problems on purposeRolling SAFE-TS out onto an existing codebase? Adopting SAFE-TS covers incremental migration with // @safe-ts legacy and escape-hatch baselines, or hand the migration skill straight to your coding agent.
SAFE-TS is opinionated by design: some patterns that take three lines elsewhere take twenty here. Read the overview for what it guarantees—and exactly where its static boundaries lie.