Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use typings for d3-tip in typescript 2.0

I want to use d3-tip library to add tooltips in my charts.

Using Typescript 2.0, I added the typings for d3-tip as follows:

npm install @types/d3-tip --save

It shows up in my package.json:

"dependencies": {
  "@types/d3": "^4.7.0",
  "@types/d3-tip": "^3.5.4",
}

index.d.ts for d3-tip looks like this:

import {Primitive} from "d3";

declare module "d3" {
    type TooltipDirection = ("n" | "s" | "e" | "w" | "nw" | "ne" | "sw" | "se");
    interface Tooltip {
        hide(): Tooltip;
        show(): Tooltip;
        destroy(): Tooltip;
        ....
    }
    export function tip(): Tooltip;
}

My question is, how do I now use this/import in my code? I tried adding following:

import * as tip from 'd3-tip';   OR
import * from 'd3-tip';          OR
import { tip } from 'd3-tip';

but none of them work, and I don't get any intellisense on d3.tip().

How do I make it work? Thanks.

like image 360
Akshay Khot Avatar asked Apr 10 '17 22:04

Akshay Khot


1 Answers

Import, which works for me:

import d3Tip from "d3-tip";
const tip = d3Tip();

However, there is small discussion about this here.

like image 83
lesyk Avatar answered Oct 18 '22 08:10

lesyk