Skip to content

Zod 4 support for @tanstack/zod-adapter (specifically fallback) #4322

@ptts

Description

@ptts

Update 2025-07-16:
Nice! With the newest update from zod a new zod update coming out (hopefully) soon, fallback is not will not be necessary anymore! 🎊 (More infos)


Discussion: #4092

Which project does this relate to?

Router (@tanstack/zod-adapter)

Describe the bug

It appears that fallback from @tanstack/zod-adapter isn't ready for Zod v4.
More information about the expected behavior is in my comment below: #4322 (comment)

Steps to Reproduce the Bug or Issue

import { z } from "zod/v4";
import { fallback, zodValidator } from "@tanstack/zod-adapter";

const searchParamSchema = z.object({
  test: fallback(z.string().optional(), null).default(null),
//               ^ ❗ Type Error at z.string().optional()
});

Type Error:

Argument of type 'ZodOptional<ZodString>' is not assignable to parameter of type 'ZodTypeAny'.
  Type 'ZodOptional<ZodString>' is missing the following properties from type 'ZodType<any, any, any>': _type, _parse, _getType, _getOrReturnCtx, and 7 more.ts(2345)

Expected behavior

Zod 4 support

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions