The interfaces for extent don't seem to cover the common date extent scenario - I can see there's one covering generics with a generic argument accessor but it's return type is still limited to 'primitive' (toString()-able) or the original object type 'U' - not a date typed property of U.
In any case the standard x.domain(d3.extent(data, d=> d.date)) where data is an array of objects currently gives type errors in typescript - maybe this fix is a very specific case and there's a better generic way to approach, but I can see there are already dedicated overloads for [number, number] and [string, string]
Given `selection.datum((d,i,o) => 'string')`, TypeScript would always use the first overload, when it should be using the second. Correcting the order fixes this.
* Added empty() and size() methods to interface Enter<Datum>. As per D3 API these methods are defined on the enter selection.
* Added test function testEnterSizeEmpty() for .enter().empty() and .enter.size() methods.
The signature of Transition.styleTween is currently:
styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => Primitive, priority?: string): Transition<Datum>; (line 833)
Note that the tween is said to return a Primitive. This seems incorrect, both in terms of D3 intent and implementation.
The *correct* version appears to be:
styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive, priority?: string): Transition<Datum>;
(This is similar to similar to Transition.attrTween.)
First, the documentation states:
>>> The return value of tween must be an interpolator: a function that maps a parametric value t in the domain [0,1]
>>> to a color, number or arbitrary value.
Second, the source code of d3 3.5.5 has:
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
function styleTween(d, i) {
var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) {
this.style.setProperty(name, f(t), priority);
};
}
return this.tween("style." + name, styleTween);
};
Note the line "this.style.setProperty(name, f(t), priority);" where the result f of applying the tween is passed a parameter t.
The only point of discussion might be the type of the return value of the tween's interpolator output. Is it Primitive or any? The documentation quoted above (incidentally the same for attrTween and styleTween) explicitly allows for an arbitrary value. I don't have enough D3 experience to know if this is a practically relevant possibility.
Many thanks for your great work on d3.d.ts!!! Especially the use of tweens and interpolators perfectly illustrates the benefits of Typescript.
Best wishes,
Matthias