Next.js Discord

Discord Forum

The correct type for searchParams

Answered
Arya posted this in #help-forum
Open in Discord
What is the correct type I need to use to correctly use searchParams? I used any but obviously using that just missed the whole point of TypeScript.
export default async function Success({ searchParams } : { searchParams: any}) {
  const { session_id } = await searchParams
Answered by chisto
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>

according to docs
https://nextjs.org/docs/app/guides/upgrading/version-15#asynchronous-page
View full answer

9 Replies

@Atlantic salmon This should theoretically be of type `URLSearchParams`
I tried URLSearchParams, but then this error pops out
Should I redefine the URLSearchParams type?
Atlantic salmon
Does this component work if you use any anyway?
Atlantic salmon
Actually wait, is this a route handler?
Technically yes, a route handler is a part in this project
@Atlantic salmon Actually wait, is this a route handler?
it's a page that to be redirected after the route handler
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>

according to docs
https://nextjs.org/docs/app/guides/upgrading/version-15#asynchronous-page
Answer