7

我想使用d3-tip庫在我的圖表中添加工具提示。如何在打字稿2.0中使用打字的d3-tip

使用打字稿2.0,我加了分型爲d3-tip如下:

npm install @types/d3-tip --save 

它顯示在我的package.json:

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

index.d.ts爲D3-提示如下:

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; 
} 

我的問題是,我現在怎麼在代碼中使用this/import ?我嘗試添加以下內容:

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

但他們沒有工作,我沒有得到任何d3.tip()智能感知。

如何讓它工作?謝謝。

+0

嗨,你設法找出什麼了嗎? – since095

+0

對不起,不得不使用它沒有intellisense。 – akshayKhot

回答

0

進口,這對我的作品:

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

然而,關於這個here小的討論。