简体   繁体   English

typescript 中的 dc.js 类型

[英]dc.js types in typescript

I have a problem with types when I use dc.js version 4.2.7.当我使用 dc.js 版本 4.2.7 时,我遇到了类型问题。 In order to solve it I installed what seems to be the default types module for dc.js with the following command:为了解决它,我使用以下命令安装了似乎是 dc.js 的默认类型模块:

Install command I used我使用的安装命令

npm i @types/dc

My code works correctly in javascript.我的代码在 javascript 中正常工作。 However in typescript I either struggle with the types or when I use @types/dc it won't let me import the chart classes.然而,在 typescript 中,我要么与类型斗争,要么当我使用@types/dc时,它不会让我导入图表类。

It seems to me that the types module is outdated because even though it doesn't lets me import the chart classes it does let me import the old function based API that dc.js used in older versions.在我看来,类型模块已经过时了,因为即使它不允许我导入图表类,它也允许我导入基于旧 function 的 API,dc.js 在旧版本中使用。

How can I solve this issue?我该如何解决这个问题?

After doing some search I found that what the user Gordon in the comment above was saying is indeed true.经过一番搜索,我发现上面评论中的用户 Gordon 所说的确实是真的。 @types/dc for dc v4 is outdated and it won't work correctly. dc v4 的@types/dc已过时,无法正常工作。

A quick, dirty way of at least handling the types warnings would be to simply declare the module like so:至少处理类型警告的一种快速、肮脏的方法是简单地声明模块,如下所示:

dc.d.ts dc.d.ts

declare module "dc";

Some where accessible for your typescript transpiler can access it typescript 转译器可以访问的一些地方可以访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM