Skip to content
Source
Sign inSign up
TanStack/query

[vue-query] `queryOptions` does not allow non-getter `enabled` property #10458

Closedyschroe(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

Hello,

since #10452 (v5.98.0) the queryOptions helper function does not work with non-getter enabled properties anymore.

I think I am running into the problem mentioned by CodeRabbit in the PR: https://github.com/TanStack/query/pull/10452#discussion_r3068236648

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-dd82rg7b?file=src%2Fmain.ts

Steps to reproduce

This code throws a typescript error:

function createDefaultQueryOptions() {
    const enabled = computed(() => true);

    return queryOptions({
        queryKey: ['key'],
        queryFn: () => Promise.resolve(1),
        enabled,
    });
}

// Throws "Object literal may only specify known properties, and 'queryKey' does not exist in type '() => UndefinedInitialQueryOptions_alias_1<unknown, Error, unknown, readonly unknown[]>'.ts(2769)"

If I change the code to pass a getter as enabled or remove enabled from the options, it works again:

function createDefaultQueryOptions() {
    return queryOptions({
        queryKey: ['key'],
        queryFn: () => Promise.resolve(1),
        enabled: () => true,  // getter or remove from options
    });
}

Expected behavior

It should work with non-getter enabled, e.g. with computed properties to allow dependent queries as described here.

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

  • OS: MacOs
  • Chrome 146.0.7680.178

Tanstack Query adapter

vue-query

TanStack Query version

v5.99.0

TypeScript version

v6.0.2

Additional context

No response

Sign in to join this conversation.