12 Replies
Psuedo-code-ish but I can also paste a reproducible example
"skip" as const
is my guess
@ian
!
ah, I think you would need skip to be ["skip"] and pass it in as ...skip
the optional rest args is an array to handle varargs
What I actually want to do is have a const which can be either
"skip"
or the args
Maybe spreading would work either way?
I figured it has something to do with the rest param business, but I don't quite understand itYeah spreading allows you to have 1 arg when args are required, and 0 args when your args are {}.
So it's either ["skip"] [args] or []
but you could maybe just have the type of
OptionalRestArgsOrSkip<any>[0]
without the array
gotta runHmm
Side note, these fancy types are mostly for allowing
useQuery(api.takesNoArgs)
but disallowing useQuery(api.takesArgs)
. If you're writing your own hooks or wrappers you can simplify this if you're willing to disallow the useQuery()
syntax with a single argument.I'm probably just going to give up on typing this the safe way ultimately, but forget about inference—I can't even figure out what type TypeScript expects here.
Should I know this? Maybe I'm just a noob?
Nah this took me a while to figure out last week
What's the goal here? I may be able to write up an example
I'm writing a variant of the
usePaginatedQuery
hook which only holds results for one page at a time, but keeps track of previous cursors to support navigating forward and backwards through adjacent pages. Here's what I have so far (it's not finished)See the
mergeArgs
function
And directly below