Skip to content
Sarj Code Standards

no-zod-parse-typed-object

Reuse known object contracts instead of parsing them again with Zod.

Why

Parsing a typed service result duplicates its object contract and adds runtime validation and copying throughout trusted application code. Validate unknown data once at its boundary.

Fix

Use the typed value directly. If defaults or normalization are needed, express that mapping explicitly. Keep untrusted boundary data unknown until it is validated.

Examples

Before — flagged Reuse the typed service response
src/value.ts
import { z } from "zod";
const RowSchema = z.object({ id: z.string() });
declare function load(): Promise<{ id: string }>;
export async function read() {
return RowSchema.parse(await load());
}
After — preferred Validate unknown data once
src/value.ts
import { z } from "zod";
const RowSchema = z.object({ id: z.string() });
export function read(raw: unknown) {
return RowSchema.parse(raw);
}

References