Skip to content

Promise for typeof searchParamsCache.parse #750

Answered by franky47
rwieruch asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, the parse function has two overloads, one sync and one async. I guess the ReturnType takes the second one, not sure how to force it to lock onto a particular overload.. (edit: looks like we can't, source).

Alternatively, you could use the built-in parser inference helper, but it requires splitting your definition in two (parsers + cache):

import { createSearchParamsCache, parseAsString, type inferParserType } from "nuqs/server";

// Note: you could also export this if using useQueryStates
const searchParams = {
  search: parseAsString.withDefault(""),
  sort: parseAsString.withDefault(""),
}

export const searchParamsCache = createSearchParamsCache(searchParams);

export type ParsedSe…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rwieruch
Comment options

@franky47
Comment options

@rwieruch
Comment options

Answer selected by rwieruch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants