我将 @types/d3-tip 与 d3 一起使用,如下所示:
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)
基于此讨论,这种方法可能会引起争议,但它将使您能够克服错误。