Skip to content

needs-transform ​

Something that only works after the safe-ts transform, in a file that runs without it: a file that vite.config.*, vitest.config.* or vitest.workspace.* imports, directly or not, and the config itself. Reported: q(...), parseJson<T> / validate<T> / fromFields<T> / arbitrary<T>(), and prelude names (err, isErr, match, is, ...) used without an import.

Why: Vite loads its config, and every file the config imports, before any plugin runs, so safeTs() doesn't rewrite them (The Vite config). Vitest loads its config the same way. There q(...) throws "q() was not compiled", parseJson<T> has no validator, and a prelude name throws ReferenceError: err is not defined, as soon as vite dev, vite build or vitest starts. Tests of the same code pass, because their process has the transform, and tsc sees the prelude's global declarations. Nothing else says so.

❌ Rejected: scripts/vite-plugins.ts, which vite.config.ts imports

✕ Rejectedneeds-transform
ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import { isErr, q, type Result } from "@evobug_com/safe-ts-std/result";

type PortError = Enum<{ NotANumber: { text: string } }>;

declare function readPort(text: string): Result<number, PortError>;

export function devPort(text: string): Result<number, PortError> {
  const port = q(readPort(text));
  return port + 1;
}
ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import { Err as __qErr } from "@evobug_com/safe-ts-std/result"; import { isErr, q, type Result } from "@evobug_com/safe-ts-std/result";

type PortError = Enum<{ NotANumber: { text: string } }>;

declare function readPort(text: string): Result<number, PortError>;

export function devPort(text: string): Result<number, PortError> {
  const __q1 = readPort(text); if (__q1 instanceof __qErr) return __q1; const port = __q1;
  return port + 1;
}

✅ Accepted: what q becomes, written out

✓ Accepted0 diagnostics
ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import { isErr, type Result } from "@evobug_com/safe-ts-std/result";

type PortError = Enum<{ NotANumber: { text: string } }>;

declare function readPort(text: string): Result<number, PortError>;

export function devPort(text: string): Result<number, PortError> {
  const port = readPort(text);
  if (isErr(port)) return port;
  return port + 1;
}

The quick fix writes that: const x = q(make()) becomes const x = make(); and if (isErr(x)) return x;, q(make(), f) returns mapErr(x, f), return q(make()) becomes return make(). For a prelude name it adds the import. parseJson<T> has no fix: move the parsing into code the config doesn't import.

safe-ts migrate throw-to-result writes the same plain form instead of q(...) for the callers in such a file, and lists a call there in another shape (an assignment, an annotated or destructuring declaration, an unbraced if body) as needing a decision.

In such a file the other rules' quick fixes don't write q(...) either (must-use-result offers if (isErr(result)) return result, unhandled-failure doesn't offer q(unsafe(...))), they import the std names they add even with the prelude on, and prefer-q isn't reported: the if is the form this file needs.

match, is and variant work without the transform when they are imported: only the prelude's (not imported) are reported.

When it doesn't apply ​

  • The config loads the module with loadTransformed(...), or with import(): those aren't imports of the config, and loadTransformed rewrites what it loads.
  • The package.json next to the config runs Vite with --configLoader native (with NODE_OPTIONS="--import @evobug_com/safe-ts-transform/register"): Node loads the config through the loader, which rewrites it and its imports.
  • Imports of types (import type, or names used only as types) are stripped, so they load nothing.

What the rule can't see ​

  • A config outside the project. Configs are looked for in the file's directory and the directories above it, up to the project root (or the nearest package.json outside it), and then in the whole project (the directory safe-ts check runs in, the editor's workspace; not node_modules, dist and the like): a shared file that an app's vite.config.ts imports from another directory (../../scripts/reload.ts) is found. A config outside the project root isn't; safe-ts check still warns about it when it checks that app (the config warning).
  • A config by another name (vite --config vite.prod.ts), or another tool that loads files without the transform.

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