Using Typescript 2 @Types with Typescript 1.8.10

I'm currently trying to use d3-drag v4 types in my project. used Ts 1.8.10 and were not ready to switch to beta TS2.

the d3-v4 typed library is here: https://github.com/tomwanzek/d3-v4-definitelytyped

I tried to establish typing using:

typings install d3-drag=github:tomwanzek/d3-v4-definitelytyped/src/d3-drag/index.d.ts#4d09073c046b6444859c66ff441f1e7691777d0f --save 

but I get the following error:

typing ERR! called / tomwanzek / d 3-v4-definitelytyped / 47eae6d / src / d3-selection.d.ts answered 404, expecting it to be 200

I found someone asking the same question here:

https://github.com/tomwanzek/d3-v4-definitelytyped/issues/93

but it doesn’t answer my problem, because I can’t switch to ts2 yet. is there anyway using @types with TS 1.8.10?

+6
source share
3 answers

Meanwhile, I created a d.ts file to be able to use drag. there is no intellisense and no type checking, but at least I can use the drag and drop library.

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

I use it in my code as follows:

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

You can get the necessary files using

 npm install @types/d3-selection --save 

This will put the definition folder in the node_modules / @ types. Then you can copy the d3 selection folder to the typing folder and add a link to the index.d.ts file. I have not tried, because I am switching to TS2, but it looks like it should work.

0
source

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

  • All module definitions / permissions that the TS2 compiler executes to use the definitions set from npm @types are not available in TS 1.8.x
  • The definitions that you mean https://github.com/tomwanzek/d3-v4-definitelytyped are now moved to the DefinitelyTyped / types-2.0 branch. These are the ones that @types feed for @types/d3 (Standard D3 v4 Bundle), @types/d3-selection , @types/d3-drag , etc. All of them, written in the structure of the definition module, are supported only by TS 2. They also use other TS functions, for example, this typing of function contexts.

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

I hope you were able to upgrade from the moment of publication, as TS 2 is no longer a beta version.

0
source

All Articles