Skip to content

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": { "items": { "type": "string" }, "type": "array" },
"requireIdenticalShape": { "type": "boolean" }
},
"type": "object"
}