mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
d3-voronoi and d3-shape:
* d3-voronoi: Changed VoronoiPoint and VoronoiPointPair from type alias to interface with mandatory first and second elements * d3-shape: Added mandatory first and second element to SeriesPoint interface. Thanks to @gustavderdrache for the suggestion.
This commit is contained in:
4
d3-shape/index.d.ts
vendored
4
d3-shape/index.d.ts
vendored
@@ -326,10 +326,12 @@ export var symbolWye: SymbolType;
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// HACK: SeriesPoint is a [number, number] two-element Array with added
|
||||
// SeriesPoint is a [number, number] two-element Array with added
|
||||
// data and index properties related to the data element which formed the basis for the
|
||||
// SeriesPoint
|
||||
export interface SeriesPoint<Datum> extends Array<number> {
|
||||
0: number;
|
||||
1: number;
|
||||
index: number;
|
||||
data: Datum;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,9 @@ let point: d3Voronoi.VoronoiPoint;
|
||||
point[0] = 10; // x-coordinate
|
||||
point[1] = 10; // y-coordinate
|
||||
|
||||
point = [10, 10];
|
||||
// point = [10]; // fails, second element for y-coordinate missing
|
||||
// point = ['a', 'b']; // fails, wrong element type
|
||||
|
||||
// VoronoiPointPair ---------------------------------------------------
|
||||
|
||||
@@ -75,6 +78,13 @@ pointPair[0][1] = 10; // y-coordinate of first point
|
||||
pointPair[1][0] = 20; // x-coordinate of second point
|
||||
pointPair[1][1] = 10; // y-coordinate of second point
|
||||
|
||||
pointPair = [[10, 10], [50, 50]];
|
||||
|
||||
// pointPair = [[10, 10]]; // fails, second point coordinates missing
|
||||
// pointPair = [[10, 10], [50]]; // fails, one element is not of type [number, number]
|
||||
// pointPair = [[10], [50, 50]]; // fails, one element is not of type [number, number]
|
||||
// pointPair = [['a', 10], [50, 50]]; // fails, one element is not of type [number, number]
|
||||
|
||||
// VoronoiPolygon -------------------------------------------------------
|
||||
|
||||
let voronoiPolygon: d3Voronoi.VoronoiPolygon<VoronoiTestDatum>;
|
||||
|
||||
16
d3-voronoi/index.d.ts
vendored
16
d3-voronoi/index.d.ts
vendored
@@ -9,18 +9,24 @@
|
||||
|
||||
|
||||
/**
|
||||
* The Point type is defined as a cue that the array is strictly of type [number, number] with two elements
|
||||
* The VoronoiPoint interface is defined as a cue that the array is strictly of type [number, number] with two elements
|
||||
* for x and y coordinates. However, it is used as a base for interface definitions, and [number, number]
|
||||
* cannot be extended.
|
||||
*/
|
||||
export type VoronoiPoint = Array<number>;
|
||||
export interface VoronoiPoint extends Array<number> {
|
||||
0: number;
|
||||
1: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The PointPair type is defined as a cue that the array is strictly of type [[number, number], [number, number]] with two elements, one
|
||||
* The VoronoiPointPair interface is defined as a cue that the array is strictly of type [[number, number], [number, number]] with two elements, one
|
||||
* for each point containing the respective x and y coordinates. However, it is used as a base for interface definitions, and
|
||||
* [[number, number], [number, number]]cannot be extended.
|
||||
* [[number, number], [number, number]] cannot be extended.
|
||||
*/
|
||||
export type VoronoiPointPair = Array<[number, number]> // [Point, Point];
|
||||
export interface VoronoiPointPair extends Array<[number, number]> {
|
||||
0: [number, number];
|
||||
1: [number, number];
|
||||
}
|
||||
|
||||
export interface VoronoiPolygon<T> extends Array<[number, number]> {
|
||||
data: T;
|
||||
|
||||
Reference in New Issue
Block a user