【发布时间】:2017-01-26 09:53:03
【问题描述】:
我有两个这样的界面。
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'.
我做错了什么?如何创建接口数组?
【问题讨论】:
标签: javascript reactjs typescript