[英]ReactJs / Typescript How to pass an array of objects into interface props?
我有两个接口,看起来像这样。
export interface TableBoxPropsHeader{
name: string,
isIconOnly: boolean
}
export interface TableBoxProps<T> {
headerNames: TableBoxPropsHeader[],
// some stuff
}
我试图用这个定义创建一个变量,但由于某种原因它说我试图传递一个string[]
数组而不是TableBoxPropsHeader[]
数组。
private tableBoxProps: TableBoxProps<SomeType> = {
headerNames: [{name: "Name", isIconOnly:false}, {name: "Category", isIconOnly:true}],
我正在使用VSCode并且它没有抱怨上述内容。 但是npm打印出以下内容
Types of property 'headerNames' are incompatible.
Type 'string[]' is not assignable to type 'TableBoxPropsHeader[]'
Type 'string' is not assignable to type 'TableBoxPropsHeader'.
我究竟做错了什么? 如何创建接口数组?
好吧,这对我来说有些愚蠢。 错误中的另一个文件中有另一个变量。 它现在完美无缺......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.