Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types/d3-hexbin and @types/d3 coexistence as global libraries #19402

Closed
4 tasks done
hugoferreira opened this issue Aug 28, 2017 · 5 comments
Closed
4 tasks done

@types/d3-hexbin and @types/d3 coexistence as global libraries #19402

hugoferreira opened this issue Aug 28, 2017 · 5 comments

Comments

@hugoferreira
Copy link


So, I'm using d3 and d3-hexbin as global libraries:

<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-hexbin.v0.2.min.js"></script>

... and referencing them in .ts as:

/// <reference types="d3" />
/// <reference types="d3-hexbin" />

However, although this works:

const svg = d3.select('#hitmap')

... this:

const hexbin = d3.hexbin()

... fails with a :

Property 'hexbin' does not exist on type 
  'typeof "/Users/bytter/node_modules/@types/d3/index"'

By looking at the tests, I can see that:

import * as d3Hexbin from 'd3-hexbin';

Would export the hexbin() function directly into the d3Hexbin namespace, but I'm unable to figure out how to conciliate this with d3-hexbin as a global library.

@tomwanzek
Copy link
Contributor

Unfortunately, you are running into a known limitation of the TypeScript compiler.

When creating a TS definition file which is meant to export a global, one adds a line such as:

export as namespace d3;

In the definitions for D3, this line is added to the definition file that re-exports all the constituent modules of the "standard" bundle.

As a matter of TS compiler design, this statement can only be added once. Adding it a second time, e.g. in d3-hexbin, because D3 convention is to export into the same d3 global, will create a TS compiler error duplicate variable declaration. There is a lengthy discussion of this known issue in the DefinitelyTyped and TypeScript repos. See here and most importantly microsoft/TypeScript#9681.

Workaround:

So, I am afraid, the only suggestion I can make, is to write and use a custom definition file in your project which re-exports the D3 modules you require similar to the current D3 bundle definitions file and includes

export * from 'd3-hexbin';

Then you have only one d3 global which exposes the functionality you require.

@tomwanzek
Copy link
Contributor

@hugoferreira Just checking in to see what the status of the issue is on your side?

@tomwanzek
Copy link
Contributor

@hugoferreira Any update from your side? Can this issue be closed given the TS limitations/workaround outlined above, or do you require further issues management? Cheers, T

@tomwanzek
Copy link
Contributor

Is this still an issue or can it be closed? Thx for a status confirmation.

@tomwanzek
Copy link
Contributor

@andy-ms As a matter of maintaining open issues, could you kindly close this issue? There has been no update despite several inquiries. Thx in advance.

@hugoferreira Feel free to provide any new status/information to trigger a re-opening.

@ghost ghost closed this as completed Oct 16, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants