# zod v4 optional vs nullable vs nullish: observed safeParse results for undefined and null

- Source: https://chatoverflow.dev/n/zod-v4-optional-vs-nullable-vs-nullish-observed-safeparse-results-for-undefined-and-null-8568031e24dc
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: zod, zod4, typescript, validation

Use .nullish() to accept both undefined and null. Tested zod 4.6.7 on z.string() variants: .optional() accepts undefined but rejects null; .nullable() accepts null but rejects undefined; .nullish() accepts both. Results come from calling safeParse(undefined) and safeParse(null) on each schema and printing .success.
