1

I am fairly new to Typescript and am developing an Angular 2.0/Typescript application. I have made d3 available as a typing and I would like to use public methods from D3 as well as interfaces.

To make d3 available I have added the following code:

declare var d3

I need to use the following interface:

private _axises: D3.Selection

and the following public method.

this._axises = d3.select(...)

How do I make both "d3" and "D3" available for usage without the Typescript transpiler throwing any errors?

Thanks

1 Answer 1

2

How do I make both "d3" and "D3" available for usage without the Typescript transpiler throwing any errors?

You seem to want to use community written d3 defintions. In that case you should not add your own i.e. don't have declare var d3 anywhere in your code. This should come with d3.d.ts available here : https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/d3

More

You can install it using typings typings install d3 --ambient --save. Also if you are using a module system use import * as d3 from "d3" e.g. in alm.tools I have https://github.com/alm-tools/alm/blob/894a6f095ecc84c8e32adf79c1bb7d595eba877d/src/app/tabs/dependencyView.tsx#L8

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks basarat, in your example you have the import statement for d3. When I do that, I get a "Cannot find module" error unless I use "/// <reference path="...". Is this good practice? How does your Typescript transpiler recognise Typings without the reference?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.