我在创建D3饼图时遇到了问题,如果我使用:
/// < reference path="../typings/index.d.ts" />
import * as d3 from "d3";
d3.layout.pie< IData.IPie>().value(function (d) {Grunt编译很好,但是它在浏览器中失败了,它说:
无法读取未定义的属性“饼”
这是因为d3 v4使用了以下方法:
d3.pie< IData.IPie>().value(function (d) {
但如果我改变了它,试着咕哝一遍,我就会得到:
类型‘d3’上不存在ts属性‘饼’。
有什么暗示吗?
node_modules/d3: "_id":"d3@4.5.0“
类型: 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"
}
}并删除类型引用路径没有任何区别。
发布于 2017-02-10 17:47:18
基本上,与类型之间存在冲突,当我完全删除库时,它就开始工作了:
typings uninstall d3
npm uninstall typings发布于 2017-02-10 04:51:33
看起来您使用的是版本3的type,而d3版本是4。
删除已安装的def类型,然后安装以下命令
npm install @types/d3 --save-devGithub回购:https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3
https://stackoverflow.com/questions/42151545
复制相似问题