简体   繁体   English

如何在typescript 2.0中使用d3-tip的输入法

[英]How to use typings for d3-tip in typescript 2.0

I want to use d3-tip library to add tooltips in my charts. 我想使用d3-tip库在我的图表中添加工具提示。

Using Typescript 2.0, I added the typings for d3-tip as follows: 使用Typescript 2.0,我添加了d3-tip的类型如下:

npm install @types/d3-tip --save

It shows up in my package.json: 它显示在我的package.json中:

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

index.d.ts for d3-tip looks like this: index.d.ts for d3-tip看起来像这样:

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? 我的问题是,我现在如何在我的代码中使用此/ import? 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() . 但它们都不起作用,我在d3.tip()上没有得到任何智能感知。

How do I make it work? 我如何使其工作? Thanks. 谢谢。

Import, which works for me: 导入,对我有用:

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

However, there is small discussion about this here . 然而,关于这个小的讨论在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM