d3.js - d3'yi Angular2 ve TypeScript ile çalışacak şekilde yapılandırmanın doğru yolu


d3 kütüphanesini bir angular2 typescript projesine dahil etmeye çalışıyorum. d3'ü npm install d3 ile ve tip tanımlarını typing install d3 --save ile ekledim, fakat proje yerel sunucusu başlamıyor (tsc && concurrently "npm run tsc:w" "npm run lite"), şu hata ile:

typings/browser/definitions/d3/index.d.ts(3319,1): error TS2300: Duplicate identifier 'export='.
typings/browser/definitions/d3/index.d.ts(3323,1): error TS2300: Duplicate identifier 'export='.
typings/browser/definitions/d3/index.d.ts(3327,1): error TS2300: Duplicate identifier 'export='.
typings/modules/d3/index.d.ts(3319,1): error TS2300: Duplicate identifier 'export='.
typings/modules/d3/index.d.ts(3323,1): error TS2300: Duplicate identifier 'export='.
typings/modules/d3/index.d.ts(3327,1): error TS2300: Duplicate identifier 'export='.

bunlar benim yapılandırma dosyalarım:

typings.json:

{
  "ambientDependencies": {
    "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
    "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#5c182b9af717f73146399c2485f70f1e2ac0ff2b",
    "gapi": "github:DefinitelyTyped/DefinitelyTyped/gapi.auth2/gapi.auth2.d.ts"
  },
  "dependencies": {
    "d3": "registry:npm/d3#3.0.0+20160211003958"
  }
}

package.json:

{
  "name": "session-explorer",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.15",
    "systemjs": "0.19.26",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.6.10",
    "d3": "^3.0.0"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings": "^0.7.12"
  }
}

Cevap #1

Artık tipleri şu şekilde yükleyebilirsiniz:

npm install d3 --save
npm install @types/d3 --save-dev

Sonra d3'ü aşağıdaki şekilde içe aktarabilirsiniz

import * as d3 from 'd3';

Cevap #2

2017 Güncellemesi

Kurulum

d3 v3 için türlerin kurulumu:

npm install [email  --save
npm install @types/[email  --save-dev

En son d3 sürümü için tipleri yükleme (yazının yazıldığı anda v4):

npm install d3 --save
npm install @types/d3 --save-dev

Kullanım

import * as d3 from 'd3';

İlgili makaleler