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

Request for d3.js API update from v3 to v4.1.0 #9936

Closed
jnm2 opened this issue Jul 2, 2016 · 34 comments
Closed

Request for d3.js API update from v3 to v4.1.0 #9936

jnm2 opened this issue Jul 2, 2016 · 34 comments

Comments

@jnm2
Copy link

jnm2 commented Jul 2, 2016

d3/d3.d.ts /cc @gustavderdrache @borisyankov

d3.js got a major overhaul. Its API has improved considerably. See d3 v4 changes. I'm quite excited about it, but for the time being I have to stay with v3 or abandon TypeScript for a critical class.

Fascinating article by @mbostock discussing examples of poor d3.js API pre-v4 and the rationale behind v4's API: What Makes Software Good - well worth the read no matter what walk of programming you come from.

Edit: hang on- I just saw https://github.com/tomwanzek/d3-v4-definitelytyped so perhaps @tomwanzek is already taking care of this?

@tomwanzek
Copy link
Contributor

You are correct, I took a stab at writing new definitions for the wonderful D3 version 4.x.x by @mbostock. Mike has obviously been very generous with the modularization and features 🎉

I built on his documentation and code as well as the hard work by @gustavderdrache, @borisyankov and all the other contributors to the previous D3 v3 definitions on DefinitelyTyped. I would love to bring it into the community process in short order for peer-review/general use.

I experimented with some new typescript 1.9/2.0-dev features related to typing the this context of functions and some aspects related to UMD support. Had to test out some interdependencies...

I just finished a pass of the following new D3 modules including an initial set of shape tests (alphabetical order):

  • d3-axis
  • d3-brush
  • d3-chord
  • d3-color
  • d3-dispatch
  • d3-drag
  • d3-ease
  • d3-format
  • d3-interpolate
  • d3-path
  • d3-random
  • d3-scale
  • d3-selection
  • d3-shape
  • d3-time
  • d3-time-format
  • d3-timer
  • d3-transition
  • d3-zoom

Furthermore, there are some (as yet untested) draft definitions for the following modules:

  • d3-array
  • d3-collection
  • d3-force
  • d3-hierarchy
  • d3-polygon
  • d3-quadtree
  • d3-voronoi

With regard to what D3 version considers to be the standard bundle, I have deferred the following:

  • d3-geo
  • d3-dsv
  • d3-request
  • d3-queue

There is an actively maintained issues log on the repo.

Later today, I intend to post a follow-up to this brief status. There I will frame some of the specific questions I came across on how to move the above into pull-request(s) for DefinitelyTyped.

At the core this will be about migration path from typescript 1.8 to 2.0 including the future with UMD and @types.

cc: @ocombe, @mjrister

@tomwanzek
Copy link
Contributor

tomwanzek commented Jul 22, 2016

Thanks for the patience as I managed most of the status of the drafting in my repo in the interim. Here is an update or rather a suggested roadmap. I broke it out as follows:

  • D3 version 4.1.x definitions using Typescript 2.0.0+
  • D3 version 4.1.x definitions using Typescript 1.8.10
  • Further Items

Wherever, I am looking for specific input, I have tried to @ mention the right individuals to the best of my abilities in no particular order. Of course, all comments are welcome!

d3 version 4.1.x definitions using Typescript 2.0.0+

The definitions and tests for the modules of the D3v4 in the d3-v4-definitelytyped repo were written based on TS 2 from the get go.

As I understand it from the Support Typescript 2.0 issue #10072, the way to bring those into DefinitelyTyped and by propagation the @types organization is through a pull request against the types-2.0 branch.

Completed Modules

I am ready to submit a first PR for the following first batch of completed D3 modules with corresponding tests:

d3-array, d3-axis, d3-brush, d3-chord, d3-collection, d3-color, d3-dispatch, d3-drag, d3-ease, d3-format, d3-hierarchy, d3-interpolate, d3-path, d3-polygon, d3-quadtree, d3-random, d3-scale, d3-selection, d3-shape, d3-time, d3-time-format, d3-timer, d3-transition, d3-voronoi, d3-zoom

Known Issues related to the completed modules:

  1. UMD global exports: In D3 world each of these modules can be imported or used in a vanilla setting. In vanilla settings, each module exports to the same global identifier d3. Currently, using export as namespace d3; in the module-level definition files creates a compiler error for duplicate identifier, if they are in the same compilation context. I previously posted the issue on Typescript. Given how busy everyone on the TS project is making all our lives easier 😄, I have not received any feedback. @mhegazy, @RyanCavanaugh would be great to get your insight.
  2. d3-axis: I track one specific issue related to avoiding a definition-level coupling (TimeInterval interface) with d3-time, when there is no explicit source code dependency between the modules. My preference would be to move the definition over as is, carry the issue over and address it in a follow up.

Modules in Progress

The following D3 modules are in progress in the d3-v4-definitelytyped repo:

  • d3-force
  • d3-request (Pull request under review generously submitted by @Ledragon)
  • d3-geo (started as PR by @Ledragon)

We could submit those as follow-on PRs to DefinitelyTyped/types-2.0 as they become available in completed form with initial tests.

Modules Pending

The following modules of the standard D3 bundle are not yet started with new definitions:

  • d3-dsv
  • d3-queue.

For d3-dsv there is some legacy material already on DefinitelyTyped, which may or may not be a good starting point. Did not have a chance to look at it yet.

Standard D3 Bundle Definitions

D3v4 provides a standard bundle which comprises all the individual modules mentioned in the previous sections.

The d3-v4-definitelytyped repo contains a UMD definition file which (a) re-exports the individual modules to support import usage patterns, and (b) uses export as namespace d3; to provide the global.

I would add this one into one of the PRs against types-2.0.

Question: What would be the preferred approach to versioning the v4 Release (i.e. latest) against the older definitions and tests related to D3 v3.x?
@vvakame, @mhegazy, @gustavderdrache, @borisyankov your perspective would be appreciated.

d3 version 4.1.x definitions using Typescript 1.8.10

My intent was to convert the new TS 2 definitions from above into definitions for the current master branch. I.e. separate pull requests with definitions and tests which:

  • are structurally as close as possible to the definitions in TS 2, but do not use any features not supported by TS 1.8.10 (i.p. this typing of function contexts and related generics e.g. for DOM Element bindings)
  • use a definition 'module' structure which works with the traditional DefinitelyTyped master

The versioning issue for the old d3 and possibly d3-dsv definitions requires a comparable answer to the one above.

@vvakame, @mhegazy, @gustavderdrache, @borisyankov your perspective would be appreciated.

Further Items

Synchronization/Conflicts between master branch and types-2.0 branch

I am not sure how the synchronization/conflict resolution process between the two branches is set up.
I noticed that, the legacy d3 definition in types-2.0 is/was older than the version in the master branch.

I guess, the main questions are:

  1. How do we avoid that the TS2 definitions are overwritten with TS 1.8.x definitions, which by definition, pardon the pun 😉, will be less feature rich?
  2. How long will there be additional effort in maintaining definitions in two different major compiler versions?

@vvakame, @mhegazy, @gustavderdrache, @borisyankov your perspective would be appreciated.

JSDoc comments

So far, I have limited the amount of JSDoc style comments for the definitions. Triage, given the effort to just get the new definitions going. This should be done in a follow-up for better user experience.

Over to you!!!

And it goes without mention: Thanks for all your hard work on DefinitelyTyped, D3 v3 definitions and TypeScript.

@zbjornson
Copy link
Contributor

zbjornson commented Jul 22, 2016

Super awesome. I really like that you've included the Element in the selection generics.

Is it somehow possible to make these definitions coalesce on a re-exported module that contains a bundle of d3 modules? That is, if I do:

import * as d3 from "d3-selection";
import * as d3Drag from "d3-drag";
import * as d3Scale from "d3-scale";

Object.assign(d3, d3Drag, d3Scale);

export default d3;

then the re-exported d3 only has the definitions from d3-selection. This seems like the preferable way to use d3 v4 so you don't have to remember which module every method comes from. (Maybe relates to d3-v4-definitelytyped/issues/41)

I have two specific, minor comments about a def that I'll open in your repo as well.

@ocombe
Copy link

ocombe commented Jul 22, 2016

that is a really good idea @zbjornson, I agree that it would help a lot to have everything available under d3 namespace :)

@tomwanzek
Copy link
Contributor

Thanks for the feedback. @zbjornson and @ocombe. As for the bundling of D3 modules let me answer in two parts (Standard D3v4 Bundle and Custom Choice of Modules) .

Standard D3v4 Bundle

I already have a standard bundle file definition file here. It is ready to be added to the PR, but I wanted to get some guidance as per above on how to keep the legacy D3v3.x definitions available (e.g. under versioned filename or folder name, whatever is best for the tooling used to acquire definitions.)

The definition is written as a UMD module definition and supports the two use scenarios of the D3 standard bundle:

(a) Module import:

import * as d3 from 'd3';

// use as d3.??? for any property/method contained in the standard bundle

et voila...

(b) Vanilla Script

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

// use as d3.??? for any property/method contained in the standard bundle

Note that, this is the D3 behavior, in a vanilla context it exports to the d3 global. The reference types directive should make this available to your script. It draws the global from the export namespace as d3 line in the definitions.

Custom Choice of Modules

This should be more what you are aiming at.

(a) Module import:

If you are using (some of) the separate D3 module in a project using module imports, you simple create a barrel module comparable to:

// custom_bundled_d3.ts
export * from 'd3-selection';
export * from 'd3-drag';
export * from 'd3-scale';

This is in line with how D3 is written and supported by the current definitions.

You can re-export only relevant properties/methods of the individual d3-modules. If you use d3-selection and d3-transition, be mindful that d3-transition augments d3-selection.

And, using whatever relative path you have to your custom_bundled_d3 module, you simply use your barrel as:

import * as d3 from '../d3/custom_bundled_d3';

// use as d3.??? for any property/method contained in the custom bundle

(b) Vanilla Script

When using only a subset of the modules as vanilla scripts, D3's individual UMD modules are written to each export to the d3 global. I.e. they merge into it. (Previously Mike had them export to individual globals, e.g. d3_selection. He changed the behavior to allow for ease of code reuse between bundled and unbundled vanilla scripts.)

This is currently, where the first known issue 'UMD global exports' under the Completed Modules section comes in. Ideally, this scenario should be supported so that you can consume the shared d3 global as:

/// <reference types="d3-selection" />
/// <reference types="d3-drag" />
/// <reference types="d3-scale" />

// use as d3.??? for any property/method contained in the referenced modules

Ideally, I would have hoped that this is readily supportable by simple adding export namespace as d3 to the individual module definitions. It turns out that this currently creates a duplicate identifier error for d3. The individual modules and their definitions have no other shared identifiers (I made sure of that on the definitions side)

This is why I opened the issue referenced above on TypeScript, but have not seen any activity on it since I opened it. I am hoping to have this simple way supported, rather than having to write global augmentations into each module.

Hope this explains...

@ocombe
Copy link

ocombe commented Jul 22, 2016

Ah yes, I'd like the one with custom module import/export :)

@gustavderdrache
Copy link
Contributor

Oooh, now this is exciting! I'll definitely give this a look-over this weekend.

As for managing v3 and v4 -- my gut says that we should keep them side-by-side, at least for a while. It'll take a while for projects (especially larger ones) to change over since the name changes are fairly breaking.

@zbjornson
Copy link
Contributor

@tomwanzek another epic response, thank you. The export * from "d3-selection" + import * as d3 from "d3-bundle" works, not sure why that didn't work for me earlier!

@tomwanzek
Copy link
Contributor

Here is a non-epic simple one 😄 : @gustavderdrache I agree that we need a way to keep the 3.x definitions up and accessible in a well-defined way. I started the whole tour de force partly out of gratitude for the work of others before me and partly to ease the impact assessment for my own code base.

@tomwanzek
Copy link
Contributor

I have added d3-force to the completed modules and pushed it to the already existing PR #10228

@tomwanzek
Copy link
Contributor

I have added d3-queue to the completed modules and pushed it to the already existing PR #10228

@gustavderdrache
Copy link
Contributor

@tomwanzek According to the contribution guide,

In case there are multiple versions supported, the latest one will be without a version number in the file name. Older versions will be in the form of library-1.2.0.d.ts where the postfix should resemble a valid semantic version number (semver).

It seems like once you get the standard v4 bundle, you can just rename the old d3.d.ts to d3-3.5.17.d.ts, since that's the last release of the v3 series.

@tomwanzek
Copy link
Contributor

With the merge of PR #10228 the vast majority of individual D3 standard bundle modules now has a TypeScript 2 definition in the types-2.0 branch, which should flow to the npm @types org. Thanks to those who chimed in, contributed, @gustavderdrache for the review and @andy-ms for making the merge possible! Let alone the TypeScript team overall for all the great tooling.

Here is an interim status update. With respect to open items, I will focus on the structural questions rather than definition specific questions.

@mhegazy @RyanCavanaugh @andy-ms I think for the first few of issues, you might be best positioned to guide us quickly down the right path...So a huge thanks in advance.

  1. TypeScript issue 9681: This is the issue related to simply using export as namespace d3 to export from the separate D3 modules to the same d3 global as part of a UMD module definition.
  2. Legacy Definitions: I will create a second new PR against the types-2.0 branch for the following: d3-dsv, d3-request and d3 standard bundle definitions. The latter are a re-export of the relevant separate d3 modules with a UMD format and an export as namespace d3 for the shared global. This pull request will require re-naming the old d3-dsv.d.ts and d3.d.ts and their related test. @gustavderdrache pointed out the old convention. I am assuming that this is still correct in the world of npm @types definition file acquisition. If not, please advise otherwise on how we can ensure people can access the old D3 version 3.5.17 definitions.
  3. Branch Merge Conflict Prevention As we have currently addressed definitions for TS2 in the types-2.0 branch, how do we avoid them being overwritten by merge/pub jobs from master to types-2.0? For the legacy definitions currently under master for d3 and d3-dsv (which is not truly d3-dsv as we know it today). Even if we created TS 1.8.x definitions, which can be published under master, they would be a substantial step back from the definitions using TS2 features. Do we bleed them out until all of DefinitelyTyped is TS2 compatible? What is the timeline? Or do we need an alternative strategy, please advise.

For the chores discussed just before the merge of #10228. I will simply create a follow-up PR to types-2.0.

The same will be with the remaining/additional modules already on the way with contributions from @Ledragon and @gustavderdrache, we can migrate them to DT by PR.

Again, thanks to everyone who is helping to get this off the ground!!!

@tomwanzek
Copy link
Contributor

As a brief check point: Between the PRs linked to this issue, the module coverage for D3 now includes all modules in the standard D3 bundle, as well as two additional modules (d3-selection-multi and d3-hsv) in at least an initial version of TypeScript 2 definitions.

@tomwanzek
Copy link
Contributor

Updated Status Summary:

In the collaborative development repo for D3v4 definitions, I have created a more official release candidate 2.0.0-rc.2 of the reference definitions which are still the primary source for migration into DefinitelyTyped/types-2.0.

Thanks as well to the PR contributions from @Ledragon, @gustavderdrache and @arrayjam , the definitions are now baseline complete from a functional perspective.

🎉

The PRs submitted (and partially merged) against the types-2.0 branch and cross-referenced to this issue are as of now in synch with the release candidate.

While there are no definition-level functional issues open, the following still applies:

  1. the apparent "structural" issues called out above currently prevent a completion of the merge of PR D3 version 4 Legacy + Additional Module #10453 for the standard bundle definitions (d3), d3-dsv and d3-request (The latter module is held up because of its dependency on d3-dsv), and
  2. the d3 global merge from individual D3 modules i.e. scripts is still an open issue.

Those module definitions which have seen a successful merge are now also available through npm install @types/d3-selection --save etc. A caveat is the following: the major and minor version numbers on @types do not reflect the version number stated in the comments header of the DT definitions.

The relevant questions have since been opened as a distinct issue #10711.

Solution proposals to get the open items to resolution are more than welcome.

@tomwanzek
Copy link
Contributor

Status Update:
Despite several efforts to move this task to completion, the cycle times to get changes in related PRs moved through have been unfortunate to say the least.

(1) PR #10741 has been ready to merge for way over 2 weeks. Even accounting for the fix to the version parsing in types-publisher this should have been done over a week ago.

(2) PR #10947 has been spun off from the now closed PR #10453 to move d3-dsv and d3-request through. This was done right after receiving clarification that maintaining a definition for the d3 version 4 bundle and the legacy definitions for d3 is not yet supported in types-2.0 branch. This PR has been ready to merge for 10 days.

Despite several attempts to expedite the merging of these straightforward PRs there has been no success.

The structural solution to allows the d3 version 4 bundle definitions in is sorely needed. It has already led to some confusion in with angular-cli users. Not the least, because the version number in @types does not reflect v3.5.x.

To paraphrase the Hitchhiker's Guide to the Galaxy: Persistence is futile... at least, apparently so, in this case.

Contributions to escalate a resolution would be most appreciated.

@tomwanzek
Copy link
Contributor

Milestone Update

Thanks @RyanCavanaugh for merging the the two open PRs yesterday 😄 With that and after the enhancement to the version number parsing implemented by @andy-ms, I am happy to report the following:

Each module of the D3 standard bundle and a couple of add-ons (d3-selection-multi and d3-hsv) have now working TypeScript 2 definitions in the types-2.0 branch and are published with correct version numbers for use with npm install @types/d3-*** --save.

Thanks again in particular to @gustavderdrache @Ledragon and @arrayjam for their contributions to the new definitions!!! 🍻

For friends of Angular 2, I have published an initial version of a D3 Service, which also shows how the above definitions can be imported along-side the individual D3 modules:

🎉

Material Open Items

(1) The individual **d3-***** module definitions still do not expose a d3 global which merges across modules as the underlying D3 vanilla scripts would do. This is an open Issue tracked as TypeScript Issue 9681

(2) There is still no D3 version 4 definition file for the D3 standard bundle in d3 definitions folder. The folder still contains definitions for v3.5.17. This is due to the need to allow imports of the legacy definitions within DefinitelyTyped/types-2.0 by libraries still build on D3 v3.5.x. Structural support for both legacy and new version is critically required!!! See the discussion in Issue #10711.

Suggestions to address these are welcome.

Next Steps

I will do a final release on the collaborative development repo which was used as the main source for migration. Update the README completely and migrate any remaining open issues over here.

The above Material Open Items require resolution.

There has also been an ask to fully support strictNullChecks, which would require some more validation work before switching it on.

JSDoc comments enhancement should also be a key next step.

I prefer these to happen here after winding down the other repo, to avoid the continued manual synchronization effort necessary to date.

TypeScript 1.8.x definitions?

I am aware that some people have been looking for TS 1.8.x definitions for D3 version 4. While the TS2 definitions can be "backcast" in principle and published in what is still DefinitelyTyped/master There is a material effort involved at the beginning and conceivably for a certain transition support period.

There should probably also be a clean-up of *old * D3 v3.x related issues in this repo, which still ghost around.

In order to take that on, additional collaborator support would be required. Suggestions in this matter are welcome.

Cheers!

@tomwanzek
Copy link
Contributor

Given that the heavy lifting of the development of the initial definitions for the separate D3 version 4 modules is essentially done, I would recommend following up on the known open items as separate targeted issues:

Furthermore,

  • as per MSFT response to the now closed TypeScript Issue 9681, the ability to use export as namespace d3; in the individual D3 module definitions to create a merged global will not be supported. My recommendation is that developers requiring a (custom) bundle global d3 for vanilla script scenarios:
    • import the individual module definitions,
    • create a 'd.ts' file for their d3 bundle by re-exporting the individual modules and add export as namespace d3; to the bundle to create the missing global.

As for definitions for D3 v4 which can be used with TypeScript 1.8.x, as I said, if someone wants to add their effort/support, I would recommend opening a separate issue.

And that concludes today's status round-up... 😄

@tomwanzek
Copy link
Contributor

For those of us with a need for closure 😉 : I have created a final cut-over release on d3-v4-definitelytyped.

The release completes the migration of all definitions developed there to DT for future use + maintenance.

All open issues have been transferred to DT and cross-referenced to this issue. With the now final release of TS2, I do not have the intent to circle back to D3 version 4 definitions for TS 1.8.x.

Thanks again to @Ledragon, @gustavderdrache and @arrayjam for their code contributions.

Thanks as well to @RyanCavanaugh, @andy-ms, and @mhegazy for making TS and DT/@types possible.

Thanks of course as well to @mbostock for D3 in the first place. Without you pushing the envelope, this would not have been necessary... eh, possible, I mean 😄

Let's keep this relevant and current with all your support and future contributions. Starting with the already cross-referenced items. No rest for the wicked 🎉

Cheers.

@zbjornson
Copy link
Contributor

Mad props, @tomwanzek, for your dedication getting this big task done!

@jnm2
Copy link
Author

jnm2 commented Sep 28, 2016

I'm curious what the plan is for NuGet since I have projects using that. Is the idea that everyone uses npm instead of NuGet?

@tomwanzek
Copy link
Contributor

@zbjornson thanks for the props 😄 most appreciated!

@jnm2 I have no plan for NuGet, which seems in line with D3 itself. See D3 issue 1335. So I am afraid, I am not aware of a solution.

Regardless, there is still work to be done on the definitions here (see the JSDoc and strictNullChecking issues spun off from here for tracking).

I started working through the JSDoc completion task, as always collaborators on a per module basis are welcome! We can coordinate in the respective tracking issue, who tackles which.

Some were essentially done from the get go. Some I have recently completed and the PRs are in awaiting a merge.

However, I have to mind the cycles I spend on this, now that the heaviest lifting is done. As always, bug fixes and keeping it in line with D3 changes have priority over usability enhancements.

The pending validation for strictNullChecks, should be done after the JSDoc comments for a given module are in to avoid merge conflicts. However, while I would personally love to have the definitions validated and updated including the tests. There is effort involved to do it right, where the generics and interfaces come into play to determine the best way to do it. Tests also need to be updated.

Cheers.

@mootari
Copy link

mootari commented Sep 28, 2016

FYI, in d3/d3#2982 @mbostock mentioned that he'd be willing to add JSDoc documentation to the D3 source:

In the past I found JSDoc to be too rigid for some of the patterns D3 uses (such as scales, which effectively extend Function), and I like the simplicity of generating everything to a single Markdown file that can be hosted directly in the repo. On the other hand, it’d be nice not to maintain another tool, and using GitHub-hosted Markdown has limitations (e.g., the anchor fragment links to jump around the page don’t work on the mobile view, and GitHub doesn’t seem willing to fix it).

I thought it might be relevant to note.

@tomwanzek
Copy link
Contributor

@mootari Thanks for the FYI, I quickly read through the threat you referenced.

For the TypeScript users, the matter is in the process of being addressed from a consumers' perspective. I have started pushing PRs to DefinitelyTyped. Once merged these will further enhance the already available definitions files available through npm @types/d3-**** --save for use with TypeScript 2.

If you are interested have a look at the tracking issue #11366 for the relevant PRs.

While they are largely build based on the published API documents, I have kept them signature specific for overloaded methods. The benefit is simple, there is full IDE support when developing in TypeScript (hovers, argument help, peek at definition for a specific variable, method, or interface. That is on top of the type-safety aspect during development and the improved refactoring support gained from that.

@mbostock you are totally right, that formatting (line breaks) is a bit iffy (will have to fine-tune that at some point for the hover-over in the IDE). And there is effort in adding them/maintaining them.

But, by and large, it should be worthwhile. Personally, I do not consider it a replacement of the markdown API Docs in the repo. I think they serve two different use cases. Nothing in the JSDoc replaces the benefit of your examples and the single-view.

@mootari
Copy link

mootari commented Sep 28, 2016

@tomwanzek Oh, it was never my intention to invalidate any work done so far. All I wanted to point out was that there might be a chance for a joint effort to create precise and consistent descriptions, and that the ones already written by you and others could serve as an excellent basis for D3's adoption of JSDoc.
In the long term this might help to lower the maintainance effort needed to keep the definitions up to date.

As a side note, for some reason I wasn't even aware until now that DT definitions are tailored towards TypeScript (reading helps, I guess). Intellij's IDEs allow the import and use of DT definitions for vanilla JS, and that's the angle I was coming from.

@tomwanzek
Copy link
Contributor

@mootari Ueberhaupt kein Problem, naechstes mal, wenn ich zu Hause bin, gehen wir einen trinken! 😉

Besides, what you proposed for the D3 repo in your referenced issue looks sweet. I am all for the source links from the API docs 👍

I am all for joining efforts where technically possible given the available tooling.

Since I am running with VS Code as my IDE and work in TS, I was not aware that e.g. IntelliJ offers TS-d.ts file based intellisense when working in JS. (Maybe even VS Code for JS does it. I simply never tried?!) Would be great to know, once the PRs are merged and pushed to npm @types, whether they work for your environment...

@tomwanzek
Copy link
Contributor

@mootari The first major batches with JSDoc comment enhanced definitions have just been merged and are now available as usual on npm from the @types organization. Would be curious to know, if your IDE support works with them in your described setup (i.e. JS in IntelliJ)?

(Note: that I need to push a minor follow-up to duplicate the Selection interface comment in d3-transition, as the augmentation of the interface covers the comment from d3-selection)

@mootari
Copy link

mootari commented Oct 4, 2016

@tomwanzek I only did a superficial test, but: Oh boy, how amazing is that? 😃 🎉

IntelliJ (PhpStorm in my case) seems to only offer the master branch of https://github.com/DefinitelyTyped/DefinitelyTyped for direct downloads, so I had to manually add your definitions (picked the 2.0.0 release from https://github.com/tomwanzek/d3-v4-definitelytyped/releases and told PhpStorm to import the src folder).

I only tested using the d3 global, so I can't say how well it will cope with module imports. Gonna try that later (might be a while though).

@tomwanzek
Copy link
Contributor

tomwanzek commented Oct 5, 2016

@mootari sorry to hear that you have to manually bring in the type definitions into IntelliJ. Please be aware that the versions you find in DefinitelyTyped/types-2.0 are more current and contain the JSDoc comments. Since the cut-over release 2.0.0 in my old repo, I am no longer synchronizing the changes there.

If you can install files into your project using npm install, you can readily download the definitions, e.g.

npm install --save @types/d3-selection

If you need a bundle definition file which exports a d3 global have a look at issue #11367 . There is a workwaround/code snippet.

All the definitions are written with TypeScript 2 in mind, as a module structure they are not backwards compatible to 1.8.x. So I'm not sure if IntelliJ will use them for language services in a JS project. Good luck,

@tomwanzek
Copy link
Contributor

The D3 Standard Bundle definitions have just been merged and are now published.

The first version which reflects in accordance with @types semver is v4.2.37 (Note that, the patch release corresponds to the sequential published definitions count, not the d3 patch release)

By implication, using npm install @types/d3 --save finally acquires definitions corresponding to D3 v4.

Anyone, requiring the legacy definitions will have to explicitly install definitions from @types with a version in the 3.5.x range. As of this writing the last published version of definitions for D3 v3 in @types is 3.5.36.

Definitions in DefinitelyTyped/types-2.0 which still have a dependency on legacy D3 v3 have been updated to specifically require the last legacy version using a package.json stub with the necessary in PR #12256. (Some changes to their tsconfig.json files where also required)

@tomwanzek
Copy link
Contributor

As a brief follow-up, a similar package.json stub should be added for the definition in the d3 folder. It should probably pin down the module definitions down to minor version. The patch version would be impractical given the different meanings in npm @types vs the actual d3 module libraries.

In principle, the same would be advisable for each of D3 module definitions, which have dependencies on other D3 modules.

My main concern in suggesting this is maintainability. There is potential for the PR process to exhibit a responsiveness more in line with getting such things done without disproportionate effort.

That being said, and yes I am aware of the irony, I have just opened two issues for d3-geo and d3-voronoi definitions to be updated to the latest minor releases. Your chance for glory and taking one for the team 😄 Just always @ mention the authors of the affected definition file when submitting a PR for review!

@tomwanzek
Copy link
Contributor

It seems to me, this issue can be closed now. The definitions for the individual modules and the standard bundle are published in version D3 v4.3 now.

So, while there are open issues related to D3 v4, like the validation and enhancements related to strictNullChecks, ,#11365, and the JSDoc comment completion, #11366, the key purpose of this issue has been accomplished.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants