Skip to content

[v2] looseSchema rejects a Zod validator containing optional object properties in validators.run #2475

Open

Description

@HagenMorano

Describe the bug

Tested on @tanstack/react-form@2.0.0-alpha.3: When using formOptions.looseSchema, a Zod schema containing an optional object property is accepted as the loose schema but rejected when the same schema is passed to validators[].run.

The reported type error indicates that InferUnionObject changes an optional property such as:

text?: string | undefined;

into a required property whose value may be undefined:

text: string | undefined;

The same Zod schema can consequently not be used as the runtime validator.

Reproduction

import { formOptions, useForm } from '@tanstack/react-form';
import z from 'zod';

const schema = z.object({
	myProp: z.string().optional(),
});

const Test = () => {
  const form = useForm(
    formOptions.looseSchema(schema, {
      defaultValues: {},
      validators: [
        {
          triggers: ['change'],
          run: schema, // throws error
        },
      ],
    }),
  );
  return form;
};

TypeScript error

[...] Property 'myProp' is optional in type '{ myProp?: string | undefined; }' but required in type 'InferUnionObject<{}, { myProp?: string | undefined; }>'

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-pg3hqj4e?file=src%2FForm.tsx&terminal=dev

Steps to reproduce

import { formOptions, useForm } from '@tanstack/react-form'; // v2 alpha 3
import z from 'zod';

const schema = z.object({
	myProp: z.string().optional(),
});

const Test = () => {
  const form = useForm(
    formOptions.looseSchema(schema, {
      defaultValues: {},
      validators: [
        {
          triggers: ['change'],
          run: schema, // throws error
        },
      ],
    }),
  );
  return form;
};

Expected behavior

The schema passed to formOptions.looseSchema should also be accepted as a validator in validators[].run.

In particular, an optional schema property:

myProp?: string;

should remain compatible with the editable loose-schema representation, where the property may be omitted or contain undefined.

How often does this bug happen?

Always

Screenshots or Videos

No response

Platform

Linux

TanStack Form adapter

react-form

TanStack Form version

2.0.0-alpha.3

TypeScript version

7.0.2

Additional context

No response

Activity

  1. added
    type: bugThis is a bug in behaviour.
    v2This issue affects v2 as well.
    scope: coreThis issue affects the core package, meaning any adapter is also affected by it.
    area: typesThis issue affects the types of the library.
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typesThis issue affects the types of the library.scope: coreThis issue affects the core package, meaning any adapter is also affected by it.type: bugThis is a bug in behaviour.v2This issue affects v2 as well.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions