【问题标题】:d3.js Typescript Dependency Compilation Errorsd3.js Typescript 依赖编译错误
【发布时间】:2017-10-27 17:31:23
【问题描述】:

我正在使用带有 Angular、Typescript 和 d3.js(除其他外)的 Node.js 设计一个 Web 应用程序。该应用程序已启动并运行,库功能按预期工作。但是,我无法正确编译我的 Typescript 文件,因为我遇到了 d3 的类型定义错误(见下文)。

Error:(182, 27) TS2339:Property 'time' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(187, 27) TS2339:Property 'scale' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(193, 28) TS2339:Property 'svg' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(195, 47) TS2339:Property 'time' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(258, 28) TS2339:Property 'svg' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(915, 23) TS2339:Property 'svg' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(970, 25) TS2339:Property 'svg' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.
Error:(1147, 21) TS2339:Property 'svg' does not exist on type 'typeof 
  "C:/Users/my.user/project/workspace/node_modules/@types/d3/index"'.

这些属性似乎工作正常,但 typescript 编译器无法识别它们,这表明我的 @types/d3 依赖项有问题。

我使用的d3.js版本是3.4.8,@types/d3的版本是4.3.0

我确定这两个版本不匹配,但我仍然需要找到一对匹配的版本号,并提供 Typescript 无法识别的属性。

鉴于我需要访问的属性,任何人都可以推荐这些库的组合吗?我假设我对 d3 的打字在某种程度上落后了,所以也许旧版本会合适?如果有人有答案,甚至有系统的方法来找出我需要什么版本,那将非常有帮助。

【问题讨论】:

    标签: javascript typescript d3.js compilation typescript-typings


    【解决方案1】:

    我知道这个问题已经在几个月前发布了,但仍然需要回答。

    首先检查 package.json 文件中的 d3 和 @types 版本。 正如你所说,

    • 您使用的是 d3 v3.4.8,因此您应该使用 @types/d3@3.4.8。
    • 您正在使用与 d3 v4.3.0 兼容的 @types/4.3.0。

    注意:始终使用 d3 并键入相同的版本。

    用于搜索类型go to microsoft official site.

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 2015-10-03
      • 1970-01-01
      • 2016-01-11
      • 2020-01-06
      • 2019-12-05
      • 1970-01-01
      • 2016-05-26
      • 1970-01-01
      相关资源
      最近更新 更多