Reputation: 2256
I can not use the the d3 tip.
import * as d3 from "d3";
import "d3-tip";
var tool_tip = d3.tip()
I receive a such error.
Property 'tip' does not exist on type 'typeof "/home/viktor/projects/internet_trading_platform/client/node_modules/@types/d3/index"'.
I have imported the d3 tip modules have to augment the d3 module. But it does not. According to https://www.typescriptlang.org/docs/handbook/declaration-merging.html
Regards.
The d3-tip declaration is located here https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/d3-tip/index.d.ts
Upvotes: 5
Views: 2674
Reputation: 2867
Have been getting this for a long while and just thought on a workaround for it:
import * as d3 from 'd3';
Object.defineProperty(d3, 'tip', {
value: require('d3-tip')
});
Or if you prefer no require()
statements at all:
import * as d3 from 'd3';
import * as d3Tip from 'd3-tip';
Object.defineProperty(d3, 'tip', {
value: d3Tip
});
This way TypeScript won't complain anymore.
It also works fine with @types/d3@3
and @types/d3-tip@3
.
Upvotes: 0
Reputation: 31
try this.
import d3Tip from "d3-tip"
const tip = d3Tip();
tip.attr("class", "d3-tip")
.html(d => { return "html"})
Upvotes: 2
Reputation: 334
Not the best answer but for anyone who has come across this issue, a solution that worked for me is
Import the d3Tip as normal
import * as d3Tip from 'd3-tip';
then when initialising the tip
var tipObject = (<any>d3Tip)()
.attr('class', 'd3-tip')
.html('Loading...');
Upvotes: 0