Skip to content

Zod coerce does not work with remote function form #14457

@regnstr

Description

@regnstr

Describe the bug

The example from the documentation (changed to zod instead of valibot):

import { z } from 'zod';
import { form } from '$app/server';

export const setCount = form(
	v.object({
		// Zod:
		count: z.coerce.number()
	}),
	async ({ count }) => {
		// ...
	}
);

Gives the following typescript error in my editor (VS Code):

No overload matches this call.
  Overload 1 of 3, '(validate: "unchecked", fn: (data: RemoteFormInput) => unknown): RemoteForm<RemoteFormInput, unknown>', gave the following error.
    Argument of type 'ZodObject<{ count: ZodCoercedNumber<unknown>; }, $strip>' is not assignable to parameter of type '"unchecked"'.
  Overload 2 of 3, '(validate: StandardSchemaV1<RemoteFormInput, Record<string, any>>, fn: (data: Record<string, any>) => unknown): RemoteForm<RemoteFormInput, unknown>', gave the following error.
    Argument of type 'ZodObject<{ count: ZodCoercedNumber<unknown>; }, $strip>' is not assignable to parameter of type 'StandardSchemaV1<RemoteFormInput, Record<string, any>>'.
      The types of '"~standard".types' are incompatible between these types.
        Type 'Types<{ count: unknown; }, { count: number; }> | undefined' is not assignable to type 'Types<RemoteFormInput, Record<string, any>> | undefined'.
          Type 'Types<{ count: unknown; }, { count: number; }>' is not assignable to type 'Types<RemoteFormInput, Record<string, any>>'.
            Types of property 'input' are incompatible.
              Type '{ count: unknown; }' is not assignable to type 'RemoteFormInput'.
                Property 'count' is incompatible with index signature.
                  Type 'unknown' is not assignable to type 'RemoteFormInput | FormDataEntryValue | FormDataEntryValue[] | RemoteFormInput[]'.ts(2769)

I'm not sure if this is an issue with zod or SvelteKit though...

Reproduction

Unfortunately I don't know how to reproduce this since the bug is just in typescript. Pasting the code above into a new sveltekit project .remote file should reproduce it.

Logs

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 33.79 GB / 63.22 GB
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.10.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (140.0.3485.54)
    Internet Explorer: 11.0.26100.1882

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions