Skip to content

query.batch.set is not a function #14602

@bhuynhdev

Description

@bhuynhdev

Describe the bug

Intention: Do granular update/override for each "item" in a query.batch → I use the following weather.remote.ts where getTemp is a query.batch and updateTemp try to use getTemp.set to update the value granularly

Issue: The TypeScript type allows me to do getTemp(city).set(). However, upon runtime, there is error

[500] POST /
TypeError: getTemp(...).set is not a function    at eval (src/routes/weather.remote.ts:18:22)
// File: src/weather.remote.ts
import { query, command } from '$app/server';

const WEATHER = [
  { city: 'London', temp: 10 },
  { city: 'Bangkok', temp: 20 },
];

export const getTemp = query.batch('unchecked', async (cities: any[]) => {
  const lookup = new Map(WEATHER.map((w) => [w.city, w]));
  return (city: string) => lookup.get(city)!.temp;
});

export const updateTemp = command('unchecked', async (payload: any) => {
  const { city, newTemp } = payload;
  const record = WEATHER.find((w) => w.city === city);
  if (record) {
    record.temp = newTemp;
    getWeather(city).set(newTemp); // Runtime error but no TS error !!
  }
});

Expectation: Either query.batch.set is allowed and works, or the TypeScript should not allow it. (I do hope it's the former so I can granularly update my batch)

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-7yljcosr

Logs

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: ^6.1.1 => 6.1.1 
    @sveltejs/kit: ^2.43.8 => 2.43.8 
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1 
    svelte: ^5.39.8 => 5.39.8 
    vite: ^7.1.9 => 7.1.9

Severity

annoyance

Additional Information

No response

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