-
Hi there! I have the following setup with v2 with Next App Router: import { createSearchParamsCache, parseAsString } from "nuqs/server";
export const searchParamsCache = createSearchParamsCache({
search: parseAsString.withDefault(""),
sort: parseAsString.withDefault(""),
});
export type ParsedSearchParams = ReturnType<typeof searchParamsCache.parse>; Then I use the parser on page level: <MyComponent searchParams={searchParamsCache.parse(await searchParams)} /> But then I get the following type for (property) searchParams: Promise<{
readonly search: string;
readonly sort: string;
}> Shouldn't it be the following, because I awaited the Promise of searchParams in the page component already? (property) searchParams: {
readonly search: string;
readonly sort: string;
} Using the following type definition would work, but I am not sure why the change: export type ParsedSearchParams = Awaited<
ReturnType<typeof searchParamsCache.parse>
>; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Ah, the 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 ParsedSearchParams = inferParserType<typeof searchParams> |
Beta Was this translation helpful? Give feedback.
Ah, the
parse
function has two overloads, one sync and one async. I guess theReturnType
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):