- Sound mode parse<T>, pre-alpha
- Design record 0007, Accepted
TSR1501
Type '{0}' cannot be checked at runtime: {1}.
parse<T> was given a type with no runtime check, such as a function type, an abstract class or an unregistered brand. Validate a data type instead.
Rule parse<T>: parse<T> validators. Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.
What it means
parse<T> and the other @ts-r.dev/guard helpers expand into a runtime validator built from the type's declarations. Some types have no runtime check: function and constructor types, Promise, this types, conditional and mapped types that don't resolve on declarations, typeof queries, unique symbols, any and never. {1} gives the reason.
Your own classes are checked with instanceof, so the validator must be able to import the class. Abstract classes, generic classes, classes imported with import type, declare class outside a .d.ts file and unexported classes are TSR1501.
Branded types such as string & { readonly __brand: "UserId" } look like a plain string at run time. They need a predicate registered in [sound.guard] refinements; without one they're TSR1501, and the reason names the configuration key.
Example
// A function type has no runtime shape to check.
import { parse } from "@ts-r.dev/guard";
const raw: unknown = null;
const f = parse<(x: number) => string>(raw); // @expect TSR1501
export const out: string = f(1);
How to fix
- Validate a plain data type: primitives, literals, object types, arrays, tuples, unions,
Record, template literal types and the supported utility types. - For values that hold functions, validate the data part and construct the rest in code.
- For an abstract class, validate a concrete subclass. Export the class, and import it with a value import, not
import type. - For a branded type, register a predicate:
[sound.guard] refinements = { UserId = "./src/ids#isUserId" }, whereisUserIdis an exported(v: unknown) => v is UserId. The validator checks the base type, then calls it.
Sound mode is defined in design record 0007 (accepted 2026-10-15).