Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#61740 d3-transition: Fix element generic a…
Browse files Browse the repository at this point in the history
…ssumptions by @andyrichardson

* d3-transition: Fix element generic assumptions

- Remove `HTMLElement` type assumption on selected element
- Add support for typing selected element to follow idioms of other d3 packages

* Constrain by selection from generic

* Update index.d.ts

* Update index.d.ts

* Update d3-transition-tests.ts
  • Loading branch information
andyrichardson authored Aug 17, 2022
1 parent 329038a commit 59bf2ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions types/d3-transition/d3-transition-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {
ArrayLike,
BaseType,
selection,
select,
selectAll,
Expand Down Expand Up @@ -520,7 +521,7 @@ exitTransition = exitTransition

// transition(...) ----------------------------------------------------------

let topTransition: d3Transition.Transition<HTMLElement, any, null, undefined>;
let topTransition: d3Transition.Transition<BaseType, any, null, undefined>;
topTransition = d3Transition.transition('top');

// test creation from existing transition
Expand All @@ -530,7 +531,7 @@ topTransition = d3Transition.transition(enterTransition);
// tests with pre-existing datum (typed as string)
// set datum with a type of string
select('html').datum('test');
let topTransition2: d3Transition.Transition<HTMLElement, string, null, undefined>;
let topTransition2: d3Transition.Transition<BaseType, string, null, undefined>;
topTransition2 = d3Transition.transition<string>('top');
topTransition2 = d3Transition.transition<string>(enterTransition);

Expand Down
8 changes: 4 additions & 4 deletions types/d3-transition/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,21 +623,21 @@ export type SelectionOrTransition<GElement extends BaseType, Datum, PElement ext
* Returns a new transition with the specified name. If a name is not specified, null is used.
* The new transition is only exclusive with other transitions of the same name.
*
* The generic "OldDatum" refers to the type of a previously-set datum of the selected HTML element in the Transition.
* The generic "OldDatum" refers to the type of a previously-set datum of the selected element in the Transition.
*
* @param name Name of the transition.
*/
// tslint:disable-next-line:no-unnecessary-generics
export function transition<OldDatum>(name?: string): Transition<HTMLElement, OldDatum, null, undefined>;
export function transition<OldDatum>(name?: string): Transition<BaseType, OldDatum, null, undefined>;

/**
* Returns a new transition from an existing transition.
*
* When using a transition instance, the returned transition has the same id and name as the specified transition.
*
* The generic "OldDatum" refers to the type of a previously-set datum of the selected HTML element in the Transition.
* The generic "OldDatum" refers to the type of a previously-set datum of the selected element in the Transition.
*
* @param transition A transition instance.
*/
// tslint:disable-next-line:no-unnecessary-generics
export function transition<OldDatum>(transition: Transition<BaseType, any, BaseType, any>): Transition<HTMLElement, OldDatum, null, undefined>;
export function transition<OldDatum>(transition: Transition<BaseType, any, BaseType, any>): Transition<BaseType, OldDatum, null, undefined>;

0 comments on commit 59bf2ca

Please sign in to comment.