nextjs 应用程序中动态页面道具的类型是什么

问题描述 投票:0回答:1

我想为我的动态路线添加一个类型,我可以用下面用 Typescript 编写的代码中的类型“any”替换它。

export default async function DetailProduct({ params }: any) {
    const { imageAddress, title, price } = await getProductByID(params.id);

    return ...
}

nextjs 有类型吗?我用的是nextjs14

javascript reactjs next.js
1个回答
0
投票

NextJS 没有类型。但是,嘿,您可以根据您对键的使用情况来定义类型。如果您只是使用参数中的字符串

id
,只需定义如下类型:

export default async function DetailProduct({ params }:{ params : { id : string } } ) {
    const { imageAddress, title, price } = await getProductByID(params.id);

    return ...
}

来自文档

的示例
© www.soinside.com 2019 - 2024. All rights reserved.