Next.js Discord

Discord Forum

Help with TypeScript Error on Next.js Page Using Route Parameters (Only on Build)

Unanswered
Thrianta posted this in #help-forum
Open in Discord
Avatar
ThriantaOP
Hi everyone, I'm encountering a TypeScript error when building my Next.js app with npm run build. Interestingly, the app works fine when I use npm run dev. The error occurs in a dynamic route page /jobs/[id] and looks like this:
Type error: Type 'JobDetailPageProps' does not satisfy the constraint 'PageProps'.
  Types of property 'params' are incompatible.
    Type '{ id: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]

Here's a simplified version of my code:
interface JobDetailPageProps {
  params: { id: string };
}

async function JobDetailPage({ params }: JobDetailPageProps) {
  const queryClient = new QueryClient();
  await queryClient.prefetchQuery({
    queryKey: ["job", params.id],
    queryFn: () => getSingleJobAction(params.id),
  });

  return (
    <HydrationBoundary state={dehydrate(queryClient)}>
      <EditJobForm jobId={params.id} />
    </HydrationBoundary>
  );
}
export default JobDetailPage;

It seems like the params object isn't satisfying the expected PageProps constraint. I suspect there's a conflict between params and the expected type, but I'm unsure where PageProps is defined or how to fix this.

Has anyone else encountered a similar issue during build but not in development mode? Any advice would be greatly appreciated!

Thanks!

3 Replies

Avatar
i think i ran into the same problem someday and fixed it by not putting the params in theseperated interface then just put it in the function({params}:{id:string}){your function}
so your basically just not using the interface but youll have to try actually cant test it atm πŸ˜„
Avatar
I'm pretty sure thats from the nextjs15 uodate https://nextjs.org/docs/messages/sync-dynamic-apis