diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index e5c41a7e4be95..bb6b2a6bff6d5 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -66,9 +66,10 @@ export { } export type GetStaticProps< - P extends { [key: string]: any } = { [key: string]: any } + P extends { [key: string]: any } = { [key: string]: any }, + Q extends ParsedUrlQuery = ParsedUrlQuery > = (ctx: { - params?: ParsedUrlQuery + params?: Q preview?: boolean previewData?: any }) => Promise<{ @@ -76,17 +77,20 @@ export type GetStaticProps< revalidate?: number | boolean }> -export type GetStaticPaths = () => Promise<{ - paths: Array +export type GetStaticPaths< + P extends ParsedUrlQuery = ParsedUrlQuery +> = () => Promise<{ + paths: Array fallback: boolean }> export type GetServerSideProps< - P extends { [key: string]: any } = { [key: string]: any } + P extends { [key: string]: any } = { [key: string]: any }, + Q extends ParsedUrlQuery = ParsedUrlQuery > = (context: { req: IncomingMessage res: ServerResponse - params?: ParsedUrlQuery + params?: Q query: ParsedUrlQuery preview?: boolean previewData?: any diff --git a/test/integration/typescript/pages/ssg/[slug].tsx b/test/integration/typescript/pages/ssg/[slug].tsx new file mode 100644 index 0000000000000..5d6af8cfcc780 --- /dev/null +++ b/test/integration/typescript/pages/ssg/[slug].tsx @@ -0,0 +1,29 @@ +import { GetStaticPaths, GetStaticProps } from 'next' + +type Params = { + slug: string +} + +type Props = { + data: string +} + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: [{ params: { slug: 'test' } }], + fallback: false, + } +} + +export const getStaticProps: GetStaticProps = async ({ + params, +}) => { + return { + props: { data: params!.slug }, + revalidate: false, + } +} + +export default function Page({ data }: Props) { + return

{data}

+} diff --git a/test/integration/typescript/pages/ssr/[slug].tsx b/test/integration/typescript/pages/ssr/[slug].tsx new file mode 100644 index 0000000000000..ac201cbf1984a --- /dev/null +++ b/test/integration/typescript/pages/ssr/[slug].tsx @@ -0,0 +1,21 @@ +import { GetServerSideProps } from 'next' + +type Params = { + slug: string +} + +type Props = { + data: string +} + +export const getServerSideProps: GetServerSideProps = async ({ + params, +}) => { + return { + props: { data: params!.slug }, + } +} + +export default function Page({ data }: Props) { + return

{data}

+}