Using Typescript 2 @Types with typescript 1.8.10 Using Typescript 2 @Types with typescript 1.8.10 typescript typescript

Using Typescript 2 @Types with typescript 1.8.10


meanwhile i created a d.ts file to be able to use drag. no intellisense and no type check, but at least i can use the drag library.

 declare var d3Drag; declare module 'd3-drag' { export = d3Drag; }

I use it in my code like this:

import * as d3Drag from 'd3-drag';...let dragBehaivor = d3Drag.drag().on("start", dragStartFunction);


You can acquire the necessary files with

npm install @types/d3-selection --save

That will put the definition folder in node_modules/@types. You should then be able to copy the d3-selection folder to the typings folder and add the reference to the index.d.ts file there. I haven't tried it because I am moving to TS2, but it seems like it should work.


The short answer is that it is unfortunately not possible to use @types for D3 with TypeScript 1.8.x. For two reasons:

  1. The entire definitions/module resolution the TS2 compiler performs to use definitions installed from npm @types is not available in TS 1.8.x
  2. The definitions you are referring to https://github.com/tomwanzek/d3-v4-definitelytyped have now been migrated to the DefinitelyTyped/types-2.0 branch. They are the ones feeding @types for @types/d3 (Standard D3 v4 Bundle), @types/d3-selection, @types/d3-drag etc. All of them where written in a definition module structure only supported as of TS 2. They also use other TS features, like this typing of function contexts.

For these two reasons they will not be viable for TS 1.8.

Hopefully, you have been able to upgrade since you originally posted, since TS 2 is no longer beta.