简体   繁体   English

TypeScript:如何发送数组作为道具?

[英]TypeScript: how to send array as a prop?

I am sending an array of data to a component as a prop, like:我将一组数据作为道具发送到组件,例如:

<InfoTable TableInfo={tableRows} />;

Where tableRows is the array.其中tableRows是数组。

On my InfoTable component file I define my props like在我的 InfoTable 组件文件中,我定义了我的道具,例如

interface InfoTableProps {
  tableInfo: TableInfo[];
}

Which allows me to .map() through the tableInfo array, eg:这允许我通过 tableInfo 数组.map() ,例如:

let tableRow = tableInfo.map(function(tableInfoRow) {
  // Do some stuff
}

This works fine.这工作正常。 However, my compiler gets a warning on tableInfo: TableInfo[];但是,我的编译器在tableInfo: TableInfo[];上收到警告。

Cannot find name 'TableInfo'.找不到名称“TableInfo”。 TS2304 TS2304

I've tried Googling the problem of course but I just get people asking the same question.我当然试过用谷歌搜索这个问题,但我只是让人们问同样的问题。

Would anyone know how to remove this error or what it means?有人知道如何删除此错误或它的含义吗?

Don't you need to define the TableInfo type somewhere?您不需要在某处定义TableInfo类型吗?

eg例如

Interface TableInfo {
  id: number
  name: string
}

Sorry If you've already done that and its something else:-)抱歉,如果您已经这样做了,还有其他事情:-)

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

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