mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #45885 d3-selection - key function in .data may return number as well by @kum-deepak
* Test cases to demonstrate `key` function in `.data` calls returning non `string` causes failure. * Update definitions to allow `key` function in `.data` calls to return `number` apart from `string`.
This commit is contained in:
parent
d5800a35b0
commit
8a1bfb1ec0
@ -771,6 +771,21 @@ tr = d3Selection.select('body')
|
||||
.data<number[]>([{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<HTMLLIElement, number, HTMLElement, any>;
|
||||
li = d3Selection.select('li')
|
||||
.data(matrix[0], d => <number> d)
|
||||
.enter().append('li');
|
||||
|
||||
const tr1 = d3Selection.select("body")
|
||||
.append("table")
|
||||
.selectAll("tr")
|
||||
.data(matrix)
|
||||
.join("tr")
|
||||
.selectAll("td")
|
||||
.data(d => d, e => <number> e)
|
||||
.join("td")
|
||||
.text(d => d);
|
||||
|
||||
nMatrix = tr.data(); // i.e. matrix
|
||||
|
||||
let td: d3Selection.Selection<HTMLTableDataCellElement, number, HTMLTableRowElement, number[]>;
|
||||
|
||||
9
types/d3-selection/index.d.ts
vendored
9
types/d3-selection/index.d.ts
vendored
@ -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<T> or HTMLCollectionOf<T>
|
||||
* argument types
|
||||
@ -747,7 +752,7 @@ export interface Selection<GElement extends BaseType, Datum, PElement extends Ba
|
||||
* The datum for a given key is assigned to the element with the matching key. If multiple elements have the same key,
|
||||
* the duplicate elements are put into the exit selection; if multiple data have the same key, the duplicate data are put into the enter selection.
|
||||
*/
|
||||
data<NewDatum>(data: NewDatum[], key?: ValueFn<GElement | PElement, Datum | NewDatum, string>): Selection<GElement, NewDatum, PElement, PDatum>;
|
||||
data<NewDatum>(data: NewDatum[], key?: ValueFn<GElement | PElement, Datum | NewDatum, KeyType>): Selection<GElement, NewDatum, PElement, PDatum>;
|
||||
/**
|
||||
* 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<GElement extends BaseType, Datum, PElement extends Ba
|
||||
* The datum for a given key is assigned to the element with the matching key. If multiple elements have the same key,
|
||||
* the duplicate elements are put into the exit selection; if multiple data have the same key, the duplicate data are put into the enter selection.
|
||||
*/
|
||||
data<NewDatum>(data: ValueFn<PElement, PDatum, NewDatum[]>, key?: ValueFn<GElement | PElement, Datum | NewDatum, string>): Selection<GElement, NewDatum, PElement, PDatum>;
|
||||
data<NewDatum>(data: ValueFn<PElement, PDatum, NewDatum[]>, key?: ValueFn<GElement | PElement, Datum | NewDatum, KeyType>): Selection<GElement, NewDatum, PElement, PDatum>;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user