TS Errors trying to make a generic function to use with tanstack/query & gql.tada #1358
Unanswered
radiosilence
asked this question in
Q&A
Replies: 3 comments
-
Two solutions that rely on a type assertion, so profoundly non-ideal :/ export const getOptions2 = <
TDoc extends TadaDocumentNode<any, any>,
TVars extends TDoc extends TadaDocumentNode<any, infer V> ? V : never,
>(
doc: TDoc,
vars?: TVars,
) =>
queryOptions({
queryKey: [doc, vars] as const,
queryFn: ({ queryKey: [d, ...rest] }) => {
const gqlDoc = graffle.gql(d);
return gqlDoc.send(...(rest as Parameters<typeof gqlDoc.send>));
},
});
export const getOptions = <
TData extends Record<string, unknown>,
TVars extends Record<string, unknown>,
>(
doc: TadaDocumentNode<TData, TVars>,
vars?: TVars,
) =>
queryOptions({
queryKey: [doc, vars] as const,
queryFn: ({ queryKey: [d, ...rest] }) => {
const gqlDoc = graffle.gql(d);
return gqlDoc.send(...(rest as Parameters<typeof gqlDoc.send>));
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey, could you make a tiny repro repo? I’ll take a look |
Beta Was this translation helpful? Give feedback.
0 replies
-
what makes it extra hard is that almost no types from Graffle seems to be exposed in the package :/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm trying to make a generic
getOptions
function that handles a document and it's args and can be used as the argument for tanstack query's stuff. Here's my attempt so far, however I get a TS error and I'm not sure if I'm doing something wrong or the types are awkward - it works fine if I pass in concrete types!Funnily enough data/args are all inferred correctly, it's purely the
.send()
that fails.Beta Was this translation helpful? Give feedback.
All reactions