我正在使用带有Typescript和webpack的d3。
在package.json
:
"dependencies": {
"@types/d3": "^3.5.38",
"@types/d3-tip": "^3.5.5",
"d3": "^3.5.17",
"d3-tip": "^0.7.1",
...
},
在我的代码中,d3工作正常,但d3.tip()
没有。这一切都很好,但是当我在浏览器中运行代码时,我得到:
Uncaught TypeError: d3.tip is not a function
如果我在控制台中评估d3.tip
,我会得到undefined
。如果我尝试使用:
import * as d3 from "d3"
import * as d3Tip from "d3-tip";
d3.tip = d3tip
我明白了:
Cannot assign to 'tip' because it is a constant or a read-only property.
发生了什么事?如何正确使用d3.tip?
答案 0 :(得分:0)
我修正了如下:
import * as d3 from "d3"
import * as d3Tip from "d3-tip"
(d3 as any).tip = d3Tip
(d3 as any)
阻止编译器抱怨d3.tip是一个只读属性。