无法使用 @types/d3-tip:无法分配类型为"工具提示"的参数



我将 @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)

基于此讨论,这种方法可能会引起争议,但它将使您能够克服错误。

相关内容

最新更新