Next.js Discord

Discord Forum

Searchparams in server component

Unanswered
Collin posted this in #help-forum
Open in Discord
Avatar
export default async function AuthenticationPage({
  params,
  searchParams,
}: {
  params: { slug: string };
  searchParams: { [key: string]: string | string[] | undefined };
}) {}



Whenever i try to compile i get this error:

Type error: Type '{ params: { slug: string; }; searchParams: any; }' 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]

  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) {
PS C:\Users\colli\Desktop\nextjs> pnpm  i next@rc2 react@rc2 react-dom@rc2

15 Replies

Avatar
I didnt have this with nextjs 14
Avatar
params & searchParams are now async meaning they return Promises, change your types to be Promise<{ slug: string}> & Promise<{ [key: string]: string | string[] | undefined }>
Avatar
Type error: Type 'Params' 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]
Image
Avatar
Where are you accessing params the page prop, not the custom variable you made.
Avatar
Image
Nevermind im stupid
its fixed in this file, i am getting the error in another file
Image
How would u do it in generateMetadata since this is not a async function
Can you make generateMetadata async?
Avatar
Yes
It's actually rare I don't see an async generateMetadata, mind if I see what you are doing in that function?
oh it's right in my face, lol the diff confused me
getPostBySlug isn't an async function?
Avatar
Nope