Skip to content

Instantly share code, notes, and snippets.

@jln13x
Last active August 23, 2024 17:09
Show Gist options
  • Select an option

  • Save jln13x/07b2d3e47d33d7ccc8350d3cc211c7cb to your computer and use it in GitHub Desktop.

Select an option

Save jln13x/07b2d3e47d33d7ccc8350d3cc211c7cb to your computer and use it in GitHub Desktop.
Typed PageProps Helper for Next.js App Router
type R = Record<string, string>;
export type PageProps<
PathParams extends R | undefined = undefined,
SearchParams extends R | undefined = undefined,
> = {
params: PathParams extends R ? PathParams : never;
searchParams: SearchParams extends R
? Partial<{
[K in keyof SearchParams]: string | string[];
}>
: never;
};
export type Params<T extends Array<string>> = {
[K in T[number]]: string;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment