我正在使用 Next.js 15。 我声明我的页面如下:
export default async function Page({ params }: { params: { slug: string[] } })
{ ... }
但是当我尝试构建项目时,我得到:
Type error: Type '{ params: { slug: string[]; }; }' 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]
如何解决类型或忽略此错误?我已经使用了评论
// @ts-expect-error: params type does not match expected PageProps
,但它仍然没有忽略这个错误。
我做错了什么?谢谢你,Stackoverflow!
不确定这是否相关,但接下来的 15 个属性对
params
https://nextjs.org/docs/app/building-your-application/upgrading/version-15#async-request-apis 进行了重大更改-突破性改变
您可以降级或尝试等待
params
,如下所示:
type Params = Promise<{ slug: string }>
export default async function Page({ params }: { params: Params }) {
const { slug } = await params
}