Skip to content

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

@yschroe

Description

@yschroe

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:
#10452 (comment)

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

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