Skip to content

Commit

Permalink
NextPageProps (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasparus authored Dec 13, 2024
1 parent 57d75db commit 408eac6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-sloths-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theguild/components": patch
---

Add `NextPageProps` utility type
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export { PRODUCTS } from './products';
export * from './types/components';
export * from './logos';
export { cn } from './cn';
export * from './next-types';

declare module 'react' {
interface CSSProperties {
Expand Down
27 changes: 27 additions & 0 deletions packages/components/src/next-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Next.js page props type.
* @see https://nextjs.org/docs/app/api-reference/file-conventions/page#props
* @see https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#good-to-know
*/
export interface NextPageProps<
TParams extends string = never,
TSearchParams extends string = never,
> {
params: Promise<
UnionToIntersection<
{
[K in TParams]: {
[F in K extends `...${infer U}` ? U : K]: K extends `...${string}` ? string[] : string;
};
}[TParams]
>
>;
searchParams: Promise<{ [K in TSearchParams]?: string | string[] }>;
}

type Prettify<T> = { [K in keyof T]: T[K] } & {};

type UnionToIntersection<T> = Prettify<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never
>;

0 comments on commit 408eac6

Please sign in to comment.