2017-05-26 198 views
1

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

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"'. 

这些特性似乎是工作的罚款,但打字稿编译器无法识别它们,这表明有什么东西错了我的@类型/ D3依赖。

,我使用d3.js的版本是3.4.8 ,以及版本@类型/ D3是4.3.0

我敢肯定,这两个版本不匹配,但我仍然需要找到一对匹配的版本号,而且还可以提供的是打字稿是不承认的属性。

任何人都可以推荐这些库的组合,因为我需要访问的属性会工作吗?我假设我的d3类型以某种方式落后了,​​所以也许旧版本会适合?如果有人有答案,或者甚至有系统的方式来找出我需要的版本,那将是非常有用的。

回答

0

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

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

  • 您使用D3 v3.4.8所以你应该使用@类型/ D3 @ 3.4.8。
  • 您正在使用@ types/4.3.0,它将与d3 v4.3.0兼容。

注:始终以D3和类型相同的版本。

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