next.js: Next 13: Missing Types for generateStaticParams

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 Binaries: Node: 16.18.0 npm: 8.19.2 Yarn: 1.22.19 pnpm: 7.13.4 Relevant packages: next: 13.0.0 eslint-config-next: 13.0.0 react: 18.2.0 react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

No response

Describe the Bug

A next 13 app with typescript and generateStaticParams can not be build. The following code works in dev mode, but fails on build:

import { use } from "react";
import { fetchPeople, fetchPeoples } from "../../../lib/people";

type Params = {
  id: string;
};

type Props = {
  params: Params;
};

const People = ({ params }: Props) => {
  const people = use(fetchPeople(params.id));
  return (
    <>
      <h1>{people.name}</h1>
    </>
  );
};

export const generateStaticParams = async (): Promise<Params[]> => {
  const peoples = await fetchPeoples();

  const result = peoples.map((people) => ({
    id: people.id,
  }));

  return result;
}

export default People;

The build fails with the following error:

Type error: Page "app/people/[id]/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
        Expected "Props", got "PageProps".
          Invalid configuration:
            Expected "Params", got "PageParams | undefined".
              Expected "Params", got "undefined".

Sadly i was not able to find the mentioned types of the error.

Have a look at the following discussions for more informations:

Expected Behavior

The example above can be build or the required types are exported.

Link to reproduction

https://github.com/sdorra/next-13-missing-types

To Reproduce

Run pnpm build in the example repository

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 16
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@thaddeuscleo I have got it now: params and if necessary searchParams must be declared as optional, then the compiler does not complain anymore.

-  searchParams: { currentPage: number };
+  searchParams?: { currentPage: number };

With it also own separately declared props types work.

I’m currently running "next": "^13.0.3" and i still facing same issue when executing npm run build. this line of code cause the build to fail:

export default async function RoomDashboard({
  searchParams,
}: {
  searchParams: { currentPage: number };
}) {
   // page logic
}

This is the error when executing npm run build:

Type error: Page "app/room/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
        Expected "{ searchParams: { currentPage: number; }; }", got "PageProps".

I didn’t face any problem during dev(npm run dev), I’m not sure whether it’s my fault or the feature got some bugs during build time.

NextJS 13 is dope 🚀 , but there is something can be polish. thank you Nextjs Dev member have a nice day 😄. I really hope this can be sort out soon…

I’m facing the same problem during build:

type PageParams = {
  slug: string;
};

type PageProps = {
  params: PageParams;
};

export const dynamicParams = true;

export async function generateStaticParams(): Promise<PageParams[]> {
  const payload = await getNodes();

  return payload.nodes.map((node) => ({
    slug: node.path
  }));
}

export default async function NodePage({ params }: PageProps) {
  const node = await getNode(params.slug);
  if (!node) return notFound();
  return (
    <div>
      <h1>Hello, Next.js! {params.slug}</h1>
      <pre>{JSON.stringify({ node }, null, 2)}</pre>
    </div>
  );
}
...
info  - Compiled successfully
info  - Linting and checking validity of types ...Failed to compile.

Type error: Page "app/[slug]/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
          Invalid configuration:
            Expected "{ slug: string; } | undefined", got "PageParams | undefined".

@shuding Any news on this? This is preventing me from deploying.

@shuding I still seem to be getting this error. Here is the result of running next build

Screen Shot 2022-10-31 at 9 19 19 PM

Here is the file it is failing at https://github.com/gabrielgrover/improved-octo-spoon/blob/main/app/blog/[slug]/page.tsx

@gabrielgrover We already released 13.0.1, let us know if the issue is still happening!

This is still happening for me on Next 13.1.4, only during next build:

Type error: Page "app/[username]/[storySlug]/page.js" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported Page component isn't correctly typed.
        Expected "{ params: any; searchParams: any; }", got "PageProps".

app/[username]/[storySlug]/page.js

async function StoryPage({ params, searchParams }) {
  ...
}

export default StoryPage;

Changing it to the following causes the error to not happen:

app/[username]/[storySlug]/page.js

async function StoryPage(props) {
  const { params, searchParams } = props;
  ...
}

export default StoryPage;

the perfect fix It worked 😃 thank you

This is still happening for me on Next 13.1.4, only during next build:

Type error: Page "app/[username]/[storySlug]/page.js" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported Page component isn't correctly typed.
        Expected "{ params: any; searchParams: any; }", got "PageProps".

app/[username]/[storySlug]/page.js

async function StoryPage({ params, searchParams }) {
  ...
}

export default StoryPage;

Changing it to the following causes the error to not happen:

app/[username]/[storySlug]/page.js

async function StoryPage(props) {
  const { params, searchParams } = props;
  ...
}

export default StoryPage;

After updating to 13.0.1, I was still facing the issue. However, I fixed it by updating the page’s type from NextPage to FC.