繁体   English   中英

TypeScript:TS2339 错误 — 类型“对象”上不存在属性

[英]TypeScript: TS2339 error — Property does not exist on type 'object'

我无法在我的应用程序上解决此错误。 本质上,我有一个界面设置如下:

interface skuInfo {
    href: string
}

interface myObjectItem {
    itemId: string
    isFound: boolean
    price: {
        selling: number 
    }
    images: {
        sku: skuInfo[]
    }
}

让我感到震惊的是myObjectItem.images.sku

我有一个 object 设置为: const exObj: myObjectItem

当我尝试访问其属性时: exObj.images.sku[0].href ,我收到以下错误:

Property 'href' does not exist on type 'object'

在我的 Visual Code 编辑器中,我可以看到它在访问 object 的数组时预填充了href属性,但 TS 仍然在抱怨。

我错过了什么吗?

根据您的界面,属性访问应该是

exObj.images.sku[0].href
// -----------^

所以,typescript 是对的,你的图像 object 没有href属性

检查这个游乐场,你的错误不会重现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM