[英]TypeScript Compiler: @types/d3-tip - Cannot invoke an expression whose type lacks a call signature
I am trying to understand this error, read all the questions with similar error message but couldn't find anything helping. 我正在尝试理解此错误,请阅读所有具有类似错误消息的问题,但找不到任何帮助。
I am quite new to TypeScript, but getting there. 我是TypeScript的新手,但是到那里了。 I am trying to include the d3-tip module working with d3. 我试图包括与d3一起使用的d3-tip模块。 I installed @types/d3 and @types/d3-tip. 我安装了@ types / d3和@ types / d3-tip。 Now my code looks like this 现在我的代码看起来像这样
import * as d3 from 'd3';
import * as d3Tip from 'd3-tip';
console.log(d3Tip) // => print the function signature from d3-tip module
console.log(d3Tip())
// => results in error 'Cannot invoke an expression whose type lacks a call signature'
d3.tip = d3Tip
// => results in error 'Property 'tip' does not exist on type 'typeof "<my-project-path>/node_modules/@types/d3/index"''
I think I have two problems: first, I cannot call the d3-tip method, I don't really understand why if someone can explain that to me that'll be great. 我认为我有两个问题:首先,我无法调用d3-tip方法,我真的不明白为什么有人可以向我解释那会很棒。
Second, I cannot attach the d3Tip function as a new property of the d3 object (this is what I used to do with ES6, it worked great), then creating a tip with d3.tip()
. 其次,我无法将d3Tip函数附加为d3对象的新属性(这是我以前使用ES6做的,效果很好),然后使用d3.tip()
创建了一个提示。
I know I can find other solutions, like designing the tip myself (it may have taken less time ^^), but I'd rather understand how to solve this. 我知道我可以找到其他解决方案,例如自己设计笔尖(可能花费了更少的时间^^),但我宁愿了解如何解决该问题。
Any ideas? 有任何想法吗?
Good question. 好问题。 Initially I install with npm install @types/d3-tip
. 最初,我使用npm install @types/d3-tip
。 Then I need to copy ./node_modules/@types/d3-tip/index.d.ts
to ./d3-tip.d.ts
. 然后我需要将./node_modules/@types/d3-tip/index.d.ts
复制到./d3-tip.d.ts
。 Now the following code works: 现在,以下代码可以运行:
import * as d3 from "d3";
import "./d3-tip";
d3.tip().hide();
let arc = d3.arc();
So the declarations in d3-tip.d.ts
are merged into the d3 namespace as desired. 因此,可以将d3-tip.d.ts
中的声明合并到d3命名空间中。 Why it does not work without copying I have no clue. 为什么不复制就无法正常工作,我一无所知。 Any help? 有什么帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.