我是TypeScript的新手。
如何解决这个问题:
layout[self._swapEntries ? '_rows' : 'rows'].slice(0, layout.numRowsToDraw);
错误:
error TS7017: Index signature of object type implicitly has an 'any' type.
另一个问题:
let entries = rows.selectAll("g." + Legend.LEGEND_ENTRY_CLASS).data((d) => d);
错误2:
error TS2345: Argument of type '(d: {}) => {}' is not assignable to parameter of type '(datum: {}, index: number, outerIndex: number) => {}[]'.
Type '{}' is not assignable to type '{}[]'.
Property 'length' is missing in type '{}'.
答案 0 :(得分:1)
你可以做以下两件事之一:
col1 col 2
abc confirm
def confirm
ghi no
jkl no
mno confirm
pqr confirm
stu confirm
对象实现强类型定义:layout
然后将您访问的属性显式地转换为数组:
interface ILayout {
[index: string]: string[] | number, // And any other types which your object returns
numRowsToDraw: number
}
var layout = {
numRowsToDraw: 10
};