The correct type for searchParams
Answered
Arya posted this in #help-forum
AryaOP
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
according to docs
https://nextjs.org/docs/app/guides/upgrading/version-15#asynchronous-page
9 Replies
@Arya 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
Atlantic salmon
This should theoretically be of type
URLSearchParams
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?
AryaOP
Technically yes, a route handler is a part in this project
@Atlantic salmon Actually wait, is this a route handler?
AryaOP
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
according to docs
https://nextjs.org/docs/app/guides/upgrading/version-15#asynchronous-page
Answer