no-runtime-typeof
Prefer Zod boundary schemas or discriminated unions over runtime typeof checks.
Why
Representation checks spread value contracts across control flow. Specific boundary schemas and discriminated unions keep validation and the inferred application contract together.
Fix
Parse external structured input with a specific Zod schema, or model owned variants with a discriminated union. Required raw preprocessors, field-independent utilities, arbitrary metadata walkers and framework primitive unions need an exact-code local suppression explaining their contract.
Examples
function missing(value: unknown) { return typeof value === "undefined";}const isServer = typeof document === "undefined";function render(value: string | number) { return typeof value === "string" ? value : value.toString();}type Value = { kind: "text"; value: string } | { kind: "count"; value: number };function render(value: Value) { return value.kind === "text" ? value.value : value.value.toString();}declare const value: { id: string };const kind = typeof value;declare const value: { id: string };type Value = typeof value;function parse(value: unknown) { if ( typeof value === "object" && value !== null && !Array.isArray(value) && "id" in value && typeof value.id === "string" ) return { id: value.id }; throw new Error("Expected a record with a text id");}import { z } from "zod";const UserSchema = z.object({ id: z.string() });function parse(value: unknown) { return UserSchema.parse(value);}