我有一个数组对象,可以是以下对象
{
'value1': 1,
'value2': 2
}
或
{
'value1': 'a',
'value2': 'b'
}
或
{
'value1': {'sub1': 1, 'sub2': 2},
'value2': {'sub1': 1, 'sub2': 2}
}
我想这样输入:
export interface TableRow {
[key: string]: string | number | ([key: string] : string) | ([key: string] : number)
}
但它不起作用。
这是唯一可行的方法吗?
export interface TableRow {
[key: string]: string | number | object
}
答案 0 :(得分:2)
我认为最好使用两个界面整齐地完成此操作
export interface TableCell {
[key: string]: string | number
}
export interface TableRow {
[key: string]: string | number | TableCell
}
答案 1 :(得分:1)
将()
替换为{}
:
export interface TableRow {
[key: string]: string | number | { [key: string]: string } | { [key: string]: number }
}