Skip to content
React 19 · .tsx & custom hooks · JSX checked as codeDocs by Gemini 4 Neon Extra

SAFE-TS for React.
JSX checked the way it runs. ​

JSX is executable code: JSON.parse during render can throw, onClick={save} silently discards a returned Result, and an uncancelled useEffect fetch overwrites fresh data with stale responses. SAFE-TS checks .tsx components and custom hooks statically—before anything mounts.

4 + 116React rules plus every core TS rule
TSX + HooksComponents & custom React hooks
useTaskAbort-safe async state + <Match>
React 19Catches uncached use() promises

React Architecture

Four rules for predictable React components ​

01onClick={...}

JSX is code ​

Every SAFE-TS rule applies inside JSX: unhandled throws, dropped Results, and null. Event props are callbacks React invokes later with no caller around them.

02no-param-mutation

Props are borrowed ​

Props belong to the parent. Read them; notify changes through callbacks the parent passes down. Mutating a prop object in place fails no-param-mutation.

03useTask · <Match>

Async state is one value ​

Replace separate loading, error, and data states that can contradict each other with one AsyncState. useTask aborts superseded runs automatically.

04useEffect cleanup

Effects clean up ​

Every listener, interval, or request an effect starts must be torn down when dependencies change or the component unmounts—especially under StrictMode double-mounts.

Side-by-Side · Checked with tsc --strict

Before and after ​

Every pair below is a real .tsx component verified by cargo test and tsc --strict.

React ignores what event handlers return, so the Result from publish is silently lost.

✕ Rejectedmust-use-result
tsx
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

function publish(draft: string): Result<void, PublishError> {
  if (draft === "") return err(PublishError.Empty());
  if (draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
  return undefined;
}

export function Editor({ draft }: { draft: string }) {
  return <button onClick={() => publish(draft)}>Publish</button>;
}
tsx
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

function publish(draft: string): Result<void, PublishError> {
  if (draft === "") return err(({ tag: "Empty" } satisfies PublishError as PublishError));
  if (draft.length > 280) return err(({ tag: "TooLong", max: 280 } satisfies PublishError as PublishError));
  return undefined;
}

export function Editor({ draft }: { draft: string }) {
  return <button onClick={() => publish(draft)}>Publish</button>;
}

Store component state in one Enum (Editing, Rejected, Published) and handle every variant with <Match>.

✓ Accepted0 diagnostics
tsx
import { useState } from "react";
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
import { Match } from "@evobug_com/safe-ts-react/match";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

type Publishing = Enum<{ Editing: {}; Rejected: { error: PublishError }; Published: {} }>;
const Publishing = constructors<Publishing>();

function check(draft: string): Result<void, PublishError> {
  if (draft === "") return err(PublishError.Empty());
  if (draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
  return undefined;
}

export function Editor({ draft, onPublish }: { draft: string; onPublish: (text: string) => void }) {
  const [state, setState] = useState<Publishing>(Publishing.Editing());
  const publish = (): void => {
    const checked = check(draft);
    if (isErr(checked)) {
      setState(Publishing.Rejected({ error: checked.error }));
      return;
    }
    onPublish(draft);
    setState(Publishing.Published());
  };
  const button = <button onClick={publish}>Publish</button>;
  return (
    <Match
      on={state}
      Editing={() => button}
      Rejected={({ error }) => (
        <>
          {button}
          <Match
            on={error}
            Empty={() => <p>Write something first.</p>}
            TooLong={({ max }) => <p>Keep it under {max} characters.</p>}
          />
        </>
      )}
      Published={() => <p>Published.</p>}
    />
  );
}
tsx
import { useState } from "react";
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
import { Match } from "@evobug_com/safe-ts-react/match";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

type Publishing = Enum<{ Editing: {}; Rejected: { error: PublishError }; Published: {} }>;
const Publishing = constructors<Publishing>();

function check(draft: string): Result<void, PublishError> {
  if (draft === "") return err(({ tag: "Empty" } satisfies PublishError as PublishError));
  if (draft.length > 280) return err(({ tag: "TooLong", max: 280 } satisfies PublishError as PublishError));
  return undefined;
}

export function Editor({ draft, onPublish }: { draft: string; onPublish: (text: string) => void }) {
  const [state, setState] = useState<Publishing>(({ tag: "Editing" } satisfies Publishing as Publishing));
  const publish = (): void => {
    const checked = check(draft);
    if (isErr(checked)) {
      setState(({ tag: "Rejected", error: checked.error } satisfies Publishing as Publishing));
      return;
    }
    onPublish(draft);
    setState(({ tag: "Published" } satisfies Publishing as Publishing));
  };
  const button = <button onClick={publish}>Publish</button>;
  return (
    <Match
      on={state}
      Editing={() => button}
      Rejected={({ error }) => (
        <>
          {button}
          <Match
            on={error}
            Empty={() => <p>Write something first.</p>}
            TooLong={({ max }) => <p>Keep it under {max} characters.</p>}
          />
        </>
      )}
      Published={() => <p>Published.</p>}
    />
  );
}

More in Errors in handlers.

Tooling & Setup

Where it runs & how to install ​

Surface.tsx componentsCustom hooks (.ts importing react)
Vite dev server & build✅✅
safe-ts check src/main.tsx✅✅
Editor & CI (oxlint plugin)✅✅
Type checkingtsctsc

SAFE-TS complements—not replaces—eslint-plugin-react-hooks (rules of hooks, dependency arrays) and your linter's JSX key rule.

sh
npm install -D @evobug_com/safe-ts-transform @evobug_com/oxlint-plugin-safe-ts oxlint
npm install @evobug_com/safe-ts-std @evobug_com/safe-ts-react
ts
import { safeTs } from "@evobug_com/safe-ts-transform";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// safeTs before react: checks each file and rewrites q()/match() before React compiles JSX.
export default defineConfig({ plugins: [safeTs({ check: "error" }), react()] });
sh
git clone https://git.evobug.com/Evobug/Safe-Ts.git
cd Safe-Ts
npm install
npm run build
npm run dev -w examples/react

Full tsconfig, oxlint, and prelude setup is in React Setup.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra