typescriptnext.js

PageProps type resolution with basic example


I'm using Next.js 15. I declare my page as follows:

export default async function Page({ params }: { params: { slug: string[] } }) 
{ ... }

But when I try to build the project I get:

Type error: Type '{ params: { slug: string[]; }; }' does not satisfy the constraint 'PageProps'.
  Types of property 'params' are incompatible.
    Type '{ slug: string[]; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]

How to resolve types or ignore this error? I've used a comment // @ts-expect-error: params type does not match expected PageProps but still it doesn't ignore this error.

What am I doing wrong? Thank you, Stackoverflow!


Solution

  • not sure if this is related but next 15 has breaking changes for the properties like params https://nextjs.org/docs/app/building-your-application/upgrading/version-15#async-request-apis-breaking-change

    you can either downgrade or try to await the params like this:

    type Params = Promise<{ slug: string[] }>
    
    export default async function Page({ params }: { params: Params }) {  
      const { slug } = await params
    }