Switch from next JS14 to 15 getting a type issue on the page props
Answered
Morelet’s Crocodile posted this in #help-forum
Morelet’s CrocodileOP
Hello and thank you for your time I believe that I'm following the example for asynchronous page props but can't get past the build error.
here is my code:
Still learning the ropes with type script and any help would be greatly appreciated, I'm awaiting the props, please help.
Type error: Type '{ params: { courseId: number; email: string; }; }' does not satisfy the constraint 'PageProps'.
Types of property 'params' are incompatible.
Type '{ courseId: number; email: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]
32 |
33 | // Check the prop type of the entry function
> 34 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
| ^
35 |
36 | // Check the arguments and return type of the generateMetadata function
37 | if ('generateMetadata' in entry) {
Static worker exited with code: 1 and signal: null
here is my code:
import CourseContentComponent from "@/components/ui/course-content/CourseContentComponent";
import { isCourseIdValid } from "@/actions/courses";
import DOMPurify from "isomorphic-dompurify";
type Params = Promise<{ courseId: string; email: string }>
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>
export default async function Page(props: {
params: Params
searchParams: SearchParams
}) {
const params = await props.params;
const courseId = params.courseId;
const email = params.email;
const sanitizedUserEmail = DOMPurify.sanitize(decodeURIComponent(email));
const sanitizedCourseId = DOMPurify.sanitize(decodeURIComponent(courseId));
await isCourseIdValid(Number(sanitizedCourseId), sanitizedUserEmail, true);
return (
<>
<CourseContentComponent courseId={Number(sanitizedCourseId)} isAdmin={true} email={sanitizedUserEmail} />
</>
);
};
Still learning the ropes with type script and any help would be greatly appreciated, I'm awaiting the props, please help.
Answered by chisto
type Params = { courseId: string; email: string };
type SearchParams = { [key: string]: string | string[] | undefined };
export default async function Page(
props: {
params: Promise<Params>;
searchParams: Promise<SearchParams>;
}
) {
const params = (await props.params);
const courseId = params.courseId;
const email = params.email;
can you try this?
9 Replies
type Params = { courseId: string; email: string };
type SearchParams = { [key: string]: string | string[] | undefined };
export default async function Page(
props: {
params: Promise<Params>;
searchParams: Promise<SearchParams>;
}
) {
const params = (await props.params);
const courseId = params.courseId;
const email = params.email;
can you try this?
Answer
Australian Freshwater Crocodile
Yea for some reason I’ve seen people having issues with that, and it’s weird
Morelet’s CrocodileOP
I was the issue lol, I fixed it on one page then the error came up for the next page and I hadn't noticed the error was now on a different page, all is well
Ty guys for your help
@Morelet’s Crocodile I was the issue lol, I fixed it on one page then the error came up for the next page and I hadn't noticed the error was now on a different page, all is well
Australian Freshwater Crocodile
lol, thanks for clarifying.. I panicked because that seemed ok
Morelet’s CrocodileOP
I was totally missing the plot, I made a fresh project and tried it and it was working so I knew I was the problem. This is a great community though there's always lots of answers really quick
Australian Freshwater Crocodile
It’s Next.js fault too tho… the error messages and stack trace could be so much better, at least in my opinion
I’ve been hours trying to find an error and it’s right in my face, definitely the error shown in the console/modal has room for improvement
you don't have to do it manually on every page
you can run
and it fixes all pages
you can run
npx @next/codemod@latest next-async-request-api .
and it fixes all pages