jasondavies / d3-cloud

Create word clouds in JavaScript.
https://www.jasondavies.com/wordcloud/
Other
3.82k stars 1.07k forks source link

typescript typing file #137

Closed hatpick closed 6 years ago

hatpick commented 6 years ago

Hello,

Can this lib be used with typescript? Is there any typing file?

Thanks,

masscrx commented 6 years ago

@hatpick, If you want to use this lib for example with Angular and Typescript, please put .js file with this lib outside "src" folder, and then include it in .angular-cli.json in "scripts" section ex:

"scripts": ["../wordcloud.js"]

  1. Then import the d3 library like usual, but give it an alias: import * as D3 from 'd3'; (Notice: Capital D for D3)
  2. declare d3 again so you can use it for WordCloud: declare let d3: any;
  3. Use D3 for everything concerning the parent d3 library and d3 for word cloud generation alone.

Details: https://stackoverflow.com/a/42001600

hatpick commented 6 years ago

@masscrx I created a typing for it as the following:

declare module 'd3-cloud' {
    let cloud: Function;
    export = cloud;
}

then imported it:

import * as d3Cloud from 'd3-cloud';

btw, I'm using it in react+typescript.