2017-02-10 18 views
1

我有一个问题想创建一个D3饼图,我使用D3 V4,如果我使用:打字稿D3 - 物业“馅饼”的类型“的typeof D3”不存在

/// < reference path="../typings/index.d.ts" /> 
import * as d3 from "d3"; 
d3.layout.pie< IData.IPie>().value(function (d) { 

咕噜编译罚款,但它在浏览器中失败说:

无法读取的不确定

这是财产“馅饼”,因为D3 V4使用此相反:

d3.pie< IData.IPie>().value(function (d) {

但是,如果我改变它,尝试通过运行呼噜声,我得到:

[TS]住宅 '馅饼' 的类型 '的typeof D3' 不存在。

有什么暗示吗?

node_modules/D3: “_id”: “[email protected]

分型:https://raw.githubusercontent.com/types/npm-d3/a3171387d85d30049479ca880c617e63dca23afe/index.d.ts

编辑:

的package.json

{ 
    "name": "OpenCharts", 
    "description": "It's time to easier beautiful charts", 
    "version": "0.0.2", 
    "devDependencies": { 
    "@types/d3": "^4.5.0", 
    "grunt": "^0.4.5", 
    "grunt-contrib-concat": "~0.4.0", 
    "grunt-contrib-nodeunit": "~0.4.1", 
    "grunt-contrib-uglify": "~0.5.0", 
    "grunt-ts": "^6.0.0-beta.3", 
    "grunt-tslint": "^4.0.0" 
    }, 
    "author": "Chriss Mejía", 
    "license": "MIT", 
    "dependencies": { 
    "d3": "^4.4.0" 
    } 
} 

并删除类型参考路径没有区别。

回答

0

基本上与类型有冲突,当我完全删除它刚刚开始工作的库:

typings uninstall d3 
npm uninstall typings 
1

它似乎你正在使用type 3版本,和你的D3版是4

删除已安装的类型定义,然后再安装这个

npm install @types/d3 --save-dev 

Github上回购: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3

+0

我认为太多,但我仍然不能使它工作,我删除了参考路径线,它仍然不工作,这是我的package.json: '{ “名”:“ OpenCharts“, ”description“:”是时候更容易美丽的图表“, ”version“:”0.0.2“, ”devDependencies“:{ ”@ types/d3“:”^ 4.5.0“, ... }, “作家”: “CHRISS梅西亚”, “许可证”: “麻省理工学院”, “依赖”:{ “D3”: “^ 4.4.0” } }' –

相关问题