Created
November 8, 2022 15:07
-
-
Save NuroDev/2cf0f889c2dd3753b25f190f434b502b to your computer and use it in GitHub Desktop.
❗️ Next.js inferred generateStaticParams ─ Infer the type of static router parameters by, optionally, passing in your `generateStaticParams` function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type GenerateStaticParamsFn<TParams extends Array<unknown>> = () => TParams | Promise<TParams>; | |
type ArrayElement<A> = A extends ReadonlyArray<infer T> ? T : never; | |
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T; | |
interface NextPageProps< | |
TGenerateStaticParams extends GenerateStaticParamsFn<TParams> | undefined = undefined, | |
TParams extends Array<unknown> = Array<unknown>, | |
> { | |
/** | |
* **params** (Optional) | |
* | |
* The dynamic route params object from the root segment down that to that page. | |
*/ | |
params: TGenerateStaticParams extends GenerateStaticParamsFn<TParams> | |
? ArrayElement<UnwrapPromise<ReturnType<TGenerateStaticParams>>> | |
: Record<string, any> | undefined; | |
/** | |
* **searchParams** (Optional) | |
* | |
* The URL search params object. | |
* | |
* @example `acme.com/?q=cat` → `{ q: "cat" }` | |
*/ | |
searchParams?: Record<string, any>; | |
} | |
export async function generateStaticParams() { | |
return [ | |
{ | |
slug: 'hello-world', | |
}, | |
]; | |
} | |
export default async function MyPage({ params }: NextPageProps<typeof generateStaticParams>) { | |
return <></>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment