我在 d3 中使用 @types/d3-tip 如下:
self.tooltip = d3.tip()
.attr('class', 'tooltip')
.offset([-10,0])
.html(function(d: Datapoint) {
...
})
self.svg.call(self.tooltip)
这会引发错误:
error TS2345: Argument of type 'Tooltip' is not assignable to parameter of type '(sel: Selection<SVGElement>, ...args: any[]) => any'.
Type 'Tooltip' provides no match for the signature '(sel: Selection<SVGElement>, ...args: any[]): any'
我做错了什么?
最佳答案
尝试使用 as
关键字来克服类型检查器错误,如下所示:
self.svg.call(self.tooltip as any)
基于this discussion,这种方法可能会引起争议但它会让你克服错误。
关于typescript - 无法使用@types/d3-tip : Argument of type 'Tooltip' is not assignable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45563506/