2017-02-10 20 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」 } }' –

相關問題