From e192947599641722768e5834ef9ff026ce80d8c2 Mon Sep 17 00:00:00 2001 From: Piotr Monwid-Olechnowicz Date: Tue, 10 Dec 2024 18:56:52 +0100 Subject: [PATCH 1/2] Add NextPageProps utility type --- packages/components/src/index.ts | 1 + packages/components/src/next-types.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 packages/components/src/next-types.ts diff --git a/packages/components/src/index.ts b/packages/components/src/index.ts index 66bc5a3e8..379a64a06 100644 --- a/packages/components/src/index.ts +++ b/packages/components/src/index.ts @@ -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 { diff --git a/packages/components/src/next-types.ts b/packages/components/src/next-types.ts new file mode 100644 index 000000000..a856346a9 --- /dev/null +++ b/packages/components/src/next-types.ts @@ -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 = { [K in keyof T]: T[K] } & {}; + +type UnionToIntersection = Prettify< + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never +>; From 0c38d3328d098a4dbb572c0142b7801d993cee1f Mon Sep 17 00:00:00 2001 From: Piotr Monwid-Olechnowicz Date: Tue, 10 Dec 2024 18:59:31 +0100 Subject: [PATCH 2/2] Create brave-sloths-film.md --- .changeset/brave-sloths-film.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brave-sloths-film.md diff --git a/.changeset/brave-sloths-film.md b/.changeset/brave-sloths-film.md new file mode 100644 index 000000000..e0de04e3d --- /dev/null +++ b/.changeset/brave-sloths-film.md @@ -0,0 +1,5 @@ +--- +"@theguild/components": patch +--- + +Add `NextPageProps` utility type