Definitelytyped: [@types/d3] Please update types to last version of d3

Created on 7 Oct 2019  路  24Comments  路  Source: DefinitelyTyped/DefinitelyTyped

If you know how to fix the issue, make a pull request instead.

  • [X] I tried using the @types/xxxx package and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [ ] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [X] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @Ledragon @gustavderdrache @borisyankov @henriquefm

Hello, I'm using D3-schalechromatic and D3 on their lasted release:

  • D3-schalechromatic: v 1.5.0 Git
  • D3: v 5.12.0 Git

Both releases, fix d3.interpolateTurbo. I've update all my node packages to last release:

  • D3-schalechromatic: v 1.5.0 npm
  • D3: v 5.12.0 npm

Then, I compile my project and I get the next message error:
"Property 'interpolateTurbo' does not exist on type 'typeof import("c:/Git_NewWeb/IDbox-Web-Front/IDbox-Web-Graphics-Component/node_modules/@types/d3/index")'"

The version of @types/d3 in my package.json is v 5.7.2 which is the last one. In the content of "nodemodules/@types/d3/index.d.ts" a message say that is based on version 5.7.0 of D3.

I'm not able to use d3.interpolateTurbo although d3 has fixed it.

Most helpful comment

As a state of the art exercise, here is a table of where we stand:

Module | Current | Latest | Up-to-date
--|--|--|--
d3 | 5.16.0 | 6.1.1 | :x:
d3-array | 2.0.3 | 2.8.0 | :x:
d3-axis | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-brush | 2.1.0 | 2.1.0 | :heavy_check_mark:
d3-chord | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-collection | 1.0.4 | 1.0.7 | :x:
d3-color | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-contour | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-delaunay | 5.3.0 | 5.3.0 | :heavy_check_mark:
d3-dispatch | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-drag | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-dsv | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-ease | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-fetch | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-force | 2.1.1 | 2.1.1 | :heavy_check_mark:
d3-format | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-geo | 2.0.1 | 2.0.1 | :heavy_check_mark:
d3-hexbin | 0.2.2 | 0.2.2 | :heavy_check_mark:
d3-hierarchy | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-hsv | 0.1.0 | 0.1.0 | :heavy_check_mark:
d3-interpolate | 2.0.1 | 2.0.1 | :heavy_check_mark:
d3-path | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-polygon | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-quadtree | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-queue | 3.0.7 | 3.0.7 | :heavy_check_mark:
d3-random | 2.2.2 | 2.2.2 | :heavy_check_mark:
d3-request | 1.0.6 | 1.0.6 | :heavy_check_mark:
d3-require | 1.2.2 | 1.2.4 | :x:
d3-sankey | 0.11 | 0.12.3 | :x:
d3-scale | 3.0.1 | 3.2.3 | :x:
d3-scale-chromatic | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-selection | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-selection-multi | 1.0.0 | 1.0.1 | :x:
d3-shape | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-time | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-time-format | 3.0.0 | 3.0.0 | :heavy_check_mark:
d3-timer | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-transition | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-voronoi | 1.1.4 | 1.1.4 | :heavy_check_mark:
d3-zoom | 1.8.3 | 2.0.0 | :x:

I'll try getting d3-array to 2.1.0 right now. Do you think it would be useful to list all versions for a more in-depth tracking? A nice job was made in #45574 but maybe that's too detailed?

All 24 comments

Hi,
Thanks for reporting the issue. D3 types have not (or its modules) have - unfotunately - not been updated in a while, so I think the method you are trying to use is not yet available in current version. I personally don't have much time to dedicate to this lately, and I guess the same goes for the other co-authors. The ideal path would be to update each type for each missed version, with the appropriate version number, which represents quite some work...
My apologies for the delay, I can't make any commitment with regard to delays; I might move onwards at some point, and will let you know then

Hello @Ledragon , thank you for your time on this project.
Just pinging to check if you have any plans for d3 v5 type definition. Is it in the roadmap?

@gmagno Hi, I actually tried establishing a state of the art here. The next step would be to take all d3 versions and see what versions of the sub modules they correspond to. from there we could try updating version by version to have a consistent and complete API typing. Would "only" remain the work of actually developing the types. I hope/intend to take some time to work on this during this extended weekend

@Ledragon that looks like a lot of work. At least for someone that does not yet understand the effort needed and the process to actually generate all those type definitions.

I would love to be more helpful but I'm not minimally comfortable with Typescript nor D3. In fact having these type definitions allows one to learn the lib, to make less mistakes and to debug problems much much faster.

Many thanks!

It kind of is... Actualy after starting this I'm having mixed thoughts. I for example discovered that installing d3 version 5.7 or 5.8 will get you the same versions of the underlying packages... So I am starting to think that updating the underlying definitions first, and dealing with the global d3 types afterwards might be a better way to go... Especially given that d3-array v2 for example is not used in the current version of the global package

@ledragon v6 is out -- any timeline for updating the types?

No timeline, as I cant commit to it. But I don't forget about it, and will try to kick me in the butt to get things rolling. My plan (in my mind at least, let's see if it rolls) would be to try providing a version of each package per day, so that we could be up to date

As a state of the art exercise, here is a table of where we stand:

Module | Current | Latest | Up-to-date
--|--|--|--
d3 | 5.16.0 | 6.1.1 | :x:
d3-array | 2.0.3 | 2.8.0 | :x:
d3-axis | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-brush | 2.1.0 | 2.1.0 | :heavy_check_mark:
d3-chord | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-collection | 1.0.4 | 1.0.7 | :x:
d3-color | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-contour | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-delaunay | 5.3.0 | 5.3.0 | :heavy_check_mark:
d3-dispatch | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-drag | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-dsv | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-ease | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-fetch | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-force | 2.1.1 | 2.1.1 | :heavy_check_mark:
d3-format | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-geo | 2.0.1 | 2.0.1 | :heavy_check_mark:
d3-hexbin | 0.2.2 | 0.2.2 | :heavy_check_mark:
d3-hierarchy | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-hsv | 0.1.0 | 0.1.0 | :heavy_check_mark:
d3-interpolate | 2.0.1 | 2.0.1 | :heavy_check_mark:
d3-path | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-polygon | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-quadtree | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-queue | 3.0.7 | 3.0.7 | :heavy_check_mark:
d3-random | 2.2.2 | 2.2.2 | :heavy_check_mark:
d3-request | 1.0.6 | 1.0.6 | :heavy_check_mark:
d3-require | 1.2.2 | 1.2.4 | :x:
d3-sankey | 0.11 | 0.12.3 | :x:
d3-scale | 3.0.1 | 3.2.3 | :x:
d3-scale-chromatic | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-selection | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-selection-multi | 1.0.0 | 1.0.1 | :x:
d3-shape | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-time | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-time-format | 3.0.0 | 3.0.0 | :heavy_check_mark:
d3-timer | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-transition | 2.0.0 | 2.0.0 | :heavy_check_mark:
d3-voronoi | 1.1.4 | 1.1.4 | :heavy_check_mark:
d3-zoom | 1.8.3 | 2.0.0 | :x:

I'll try getting d3-array to 2.1.0 right now. Do you think it would be useful to list all versions for a more in-depth tracking? A nice job was made in #45574 but maybe that's too detailed?

@Ledragon thank you for hardworking. I'm also looking forward d3 fully rollout

I would also like to see the d3 types become up-to-date. I'm planning on working on this as I have time. Here's the order I'm planning on working on them in:

Thanks for the effort, that sounds like a plan. Try to submit PR for full versions of packages though, to keep things consistent. I'll try keeping on working on d3-array when my previous PR will be merged

@Ledragon I'm nearing the end of the non-d3-array updates. Are you planning on getting around to updating your PR or do you mind if I make my own PR for the changes?

@Methuselah96 Thanks for the hard work, I am checking your changes, and will update my PR on d3-array according to your comments

I updated the state-of-the-art table, we're almost there!

@Ledragon Thank you for all your hard work on the type updates

I have an issue in both @types/d3-array v2.1 and v2.2 (just updated) when I try to specify multiple keys in d3.group(), d3.groups(), d3.rollup(), d3.rollups().

Type error: Expected 2 arguments, but got 4.
Module: @types/d3-array v2.2
d3.group()
d3.groups()
d3.rollup()
d3.rollups()

In my local repository I changed the type definition to use the spread operator for the key parameter (sample rollup below, but all four have the same changes) but am not sure if this is good practice as I am relatively new to Typescript/programming. I no longer get the type error, but am unsure if it has ramifications for other functions.

Current definition:
export function rollup<TObject, TKey, TReduce>(a: Iterable<TObject>, reduce: (value: TObject[]) => TReduce, key: (value: TObject) => TKey): Map<TKey, TReduce>;

My changes:
export function rollup<TObject, TKey, TReduce>(a: Iterable<TObject>, reduce: (value: TObject[]) => TReduce, ...key: [...(value: TObject) => TKey]): Map<TKey, TReduce>;

@stdyrm I added the changes that make multiple keys possible to https://github.com/DefinitelyTyped/DefinitelyTyped/pull/48733.

I'm not sure that your rollup function definition would work as expected. If there's more than one key, it should return a nested map (e.g., Map<TKey1, Map<TKey2, TReduce>>) from what I understand. In my PR, I defined them up to three keys, since I'm not sure if there's a way to define how many times a type is nested based on the number of rest parameters.

@Methuselah96 Thanks! That type error has been driving me crazy on one of my projects.

Re: my changes - I'm not completely sure; but looks like the rollup accepts the "...keys" parameter as a destructured array, then the nest function iterates over the keys? Included my code (which doesn't throw errors after I changed the type file), then D3's rollup and nest functions at the bottom for reference. Anyway, I guess it doesn't really matter, since you fixed the issue.

My code:

const nested = rollup(
    data,
    (value: IEntry[]) => sum(value, (d: IEntry) => d.amount),
    (d: IEntry) => d.office,
    (d: IEntry) => d.candidateName,
    (d: IEntry) => d.expenditureCategory
);

D3 rollup function:

function rollup(values, reduce, ...keys) {
  return nest(values, identity, reduce, keys);
}

D3 nest function:

function nest(values, map, reduce, keys) {
  return (function regroup(values, i) {
    if (i >= keys.length) return reduce(values);
    const groups = new Map();
    const keyof = keys[i++];
    let index = -1;
    for (const value of values) {
      const key = keyof(value, ++index, values);
      const group = groups.get(key);
      if (group) group.push(value);
      else groups.set(key, [value]);
    }
    for (const [key, values] of groups) {
      groups.set(key, regroup(values, i));
    }
    return map(groups);
  })(values, 0);
}

Sorry if this is the wrong place. Looking for bisectCenter and bisector.center in d3-array.
I could implement them myself, but not sure how?

Edit: It was added on d3-array 2.6/2.7, so wait until 2.5 is out to work on it?

@tuuling No worries, this is probably the right place. I'm pretty fast at updating the types for each version (usually within hours of when the previous types are merged), so it's probably easier for me to just do it myself. Unfortunately the review process takes about a week for each PR, so it might be another couple weeks until 2.6/2.7 are published. I'll ping you once it is though.

@Methuselah96 You are doing the lords work. Wish I could help, but it looks like it鈥檚 mostly down to reviewers.

I made a PR for d3-array v2.7
Not sure if everything was correct, as I have not made a PR to DefinitelyTyped before.

Thanks, looks good to me, just waiting for my other PR to get merged (see PR for my comment).

Ah, didn't see that PR, sorry. I was wondering how version bump happens as I was looking your last PR.

version number bump PR reviewed, this one as well. As soon as version is bumped to 2.6, we can think about concluding 2.7

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alisabzevari picture alisabzevari  路  3Comments

jgoz picture jgoz  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments

JWT
svipas picture svipas  路  3Comments

Loghorn picture Loghorn  路  3Comments