diff --git a/types/d3-selection/d3-selection-tests.ts b/types/d3-selection/d3-selection-tests.ts index 318243dcfc..354cdbd96f 100644 --- a/types/d3-selection/d3-selection-tests.ts +++ b/types/d3-selection/d3-selection-tests.ts @@ -771,6 +771,21 @@ tr = d3Selection.select('body') .data([{test: 1}, {test: 2}]) // fails, using this data statement instead, would fail because of its type parameter not being met by input .enter().append('tr'); +let li: d3Selection.Selection; +li = d3Selection.select('li') + .data(matrix[0], d => d) + .enter().append('li'); + +const tr1 = d3Selection.select("body") + .append("table") + .selectAll("tr") + .data(matrix) + .join("tr") + .selectAll("td") + .data(d => d, e => e) + .join("td") + .text(d => d); + nMatrix = tr.data(); // i.e. matrix let td: d3Selection.Selection; diff --git a/types/d3-selection/index.d.ts b/types/d3-selection/index.d.ts index 6f9e2f93be..4d23693039 100644 --- a/types/d3-selection/index.d.ts +++ b/types/d3-selection/index.d.ts @@ -20,6 +20,11 @@ */ export type BaseType = Element | EnterElement | Document | Window | null; +/** + * KeyType serves as alias for valid types that d3 supports as key for data binding + */ +export type KeyType = string | number; + /** * A helper interface which covers arguments like NodeListOf or HTMLCollectionOf * argument types @@ -747,7 +752,7 @@ export interface Selection(data: NewDatum[], key?: ValueFn): Selection; + data(data: NewDatum[], key?: ValueFn): Selection; /** * Joins the data returned by the specified value function with the selected elements, returning a new selection that it represents * the update selection: the elements successfully bound to data. Also defines the enter and exit selections on @@ -780,7 +785,7 @@ export interface Selection(data: ValueFn, key?: ValueFn): Selection; + data(data: ValueFn, key?: ValueFn): Selection; /** * Appends, removes and reorders elements as necessary to match the data that was previously bound by `selection.data`, returning the merged enter and update selection.