T
TanStack10mo ago
flat-fuchsia

type that QueryOptions can be assigned to

Please! I've been stuck on this for far too long. I want a function to accept queryOptions as an argument.
const options = queryOptions({queryKey: ["test"]});

// Doesn't work
function test(arg: QueryOptions) {}
test(options);

// Doesn't work
function test(arg: Parameters<typeof queryOptions>[0]) {}
test(options);

// Works but ...
function test(arg: QueryOptions<unknown, Error, unknown, any[]>) {
// Than inside the function I can no longer do this
let x = queryOptions(arg)
}

// Which is annoying because this works (outside the function):
queryOptions(queryOptions({queryKey: ["test"]))
const options = queryOptions({queryKey: ["test"]});

// Doesn't work
function test(arg: QueryOptions) {}
test(options);

// Doesn't work
function test(arg: Parameters<typeof queryOptions>[0]) {}
test(options);

// Works but ...
function test(arg: QueryOptions<unknown, Error, unknown, any[]>) {
// Than inside the function I can no longer do this
let x = queryOptions(arg)
}

// Which is annoying because this works (outside the function):
queryOptions(queryOptions({queryKey: ["test"]))
2 Replies
flat-fuchsia
flat-fuchsiaOP10mo ago
Oh, and forgot to mention. queryOptions helper inside the function only stops yelling when using this approach:
function test(arg: Parameters<typeof queryOptions>[0]) {
let x = queryOptions(arg)
}
function test(arg: Parameters<typeof queryOptions>[0]) {
let x = queryOptions(arg)
}
flat-fuchsia
flat-fuchsiaOP10mo ago
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.

Did you find this page helpful?