d3.tip不是函数:webpack和打字稿 [英] d3.tip is not a function: webpack and typescript
本文介绍了d3.tip不是函数:webpack和打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有Typescript和webpack的d3.
I'm using d3 with Typescript and webpack.
在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()
则不能.一切都可以正常编译,但是当我在浏览器中运行代码时,我得到:
In my code, d3 works fine, but d3.tip()
does not. It all compiles fine, however when I run the code in my browser, I get:
Uncaught TypeError: d3.tip is not a function
如果我在控制台中评估d3.tip
,则得到undefined
.如果我尝试使用:
If I evaluate d3.tip
in the console, I get undefined
. If I try and use:
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?
What is going on? How do I use d3.tip correctly?
推荐答案
我对此进行了如下修复:
I fixed this as follows:
import * as d3 from "d3"
import * as d3Tip from "d3-tip"
(d3 as any).tip = d3Tip
(d3 as any)
防止编译器抱怨d3.tip是只读属性.
The (d3 as any)
prevents the compiler complaining that d3.tip is a readonly property.
这篇关于d3.tip不是函数:webpack和打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文