Skip to content
Sarj Code Standards

prefer-zod-infer

Derive a type from its Zod schema with z.infer instead of hand-writing a twin declaration beside it.

Why

A derived type stays synchronized when the runtime schema changes.

Fix

Replace the hand-written twin with z.infer<typeof Schema>.

Examples

Before — flagged Do not duplicate the schema shape
src/user.ts
import { z } from "zod";
const UserSchema = z.object({ id: z.string() });
interface User {
id: string;
}
After — preferred Infer the schema type
src/user.ts
import { z } from "zod";
const UserSchema = z.object({ id: z.string() });
type User = z.infer<typeof UserSchema>;

Options

{
"additionalProperties": false,
"properties": {
"ignoreTypeNames": {
"description": "Regular expression patterns for type names to leave unchanged.",
"items": { "type": "string" },
"type": "array"
},
"requireIdenticalShape": {
"description": "Require the schema output and declared type to have identical property shapes.",
"type": "boolean"
}
},
"type": "object"
}