Skip to content

query.batch returned function input type is mismatched #15112

@HarshNarayanJha

Description

@HarshNarayanJha

Describe the bug

From the docs, query.batch accepts a validator, which lets say accepts TypeA and validates it to TypeB (e.g. string to Date), the remote func will accept an array of TypeB, it will fetch all of them in a single db call, and then it must return a function, which accepts two params, first of type TypeB and second index of type number. The batch function itself should be called with a single TypeA variable.

Typescript does confirm this behavior, and the returned function's argument type is supposed to be validated TypeB, but this is not the case, and it is TypeA regardless of the validation library and the method of validation.

Reproduction

  1. Create a sveltekit project, enable remote functions and async
  2. Make a query.batch function that has a v.pipe(v.string(), v.toDate()) or z.coerce.date<string>() or similar two-type validator.
  3. Check the expected vs actual type of the first parameter in the return function

REPL Link: https://stackblitz.com/edit/sveltejs-kit-template-default-w1gdqvws?file=src%2Froutes%2Ftest.remote.ts

Uncommenting line 17 results in an internal error, since x is actually a string, as opposed to a date.

Logs

4:04:18 PM [vite] (ssr) page reload src/routes/test.remote.ts
[
  2026-01-01T00:00:00.000Z,
  2025-12-01T00:00:00.000Z,
  2025-11-01T00:00:00.000Z
] object
{
  '2026-01-01T00:00:00.000Z': 2026,
  '2025-12-01T00:00:00.000Z': 2025,
  '2025-11-01T00:00:00.000Z': 2025
}
X 2026-01-01 string
X 2025-12-01 string
X 2025-11-01 string

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.0 
    @sveltejs/kit: ^2.49.2 => 2.49.2 
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1 
    svelte: ^5.46.1 => 5.46.1 
    vite: ^7.2.2 => 7.3.0

Severity

serious, but I can work around it

Additional Information

The system info is from the repl, please tell me if I need to provide mine. I am already using the latest versions of svelte* packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions