簡體   English   中英

"類型“對象”TypeScript 上不存在屬性“名稱”"

[英]Property 'name' does not exist on type 'object' TypeScript

我有這個 array.map 函數:

{props.help.map((e, i) => {
return <a key={i}>{e.name}</a>
})}

{e} 對象有 'name' 和 'href' 鍵

我得到“類型'對象'上不存在屬性'名稱'”(打字稿)

我是打字稿的初學者。

您需要將對象強制轉換為any<\/code>類型,或者最佳做法是添加類型定義。

interface ExampleObject {
    name: string;
}

Help<\/code>對象創建一個接口,並在你的 props 定義中使用它:

interface Help {
  name: string;
  // other properties
}

interface Props {
  help: Help[];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM