Skip to content

no-redundant-optional-array-default

Remove .optional() immediately inside a Zod array default.

Why

An outer default already accepts undefined array input, so the inner optional wrapper adds no state or fallback behavior.

Fix

Keep the array default and remove the immediately preceding .optional() call.

Examples

Before — flagged Do not wrap a defaulted list in a redundant optional
src/schema.ts
import { z } from "zod";
const Items = z.array(z.string()).optional().default([]);
After — preferred Default an omitted list directly
src/schema.ts
import { z } from "zod";
const Items = z.array(z.string()).default([]);
Autofix output
src/schema.ts
import { z } from "zod";
const Items = z.array(z.string()).default([]);