From 3575365f13fac1904be48d84ca867dfbe3dcd258 Mon Sep 17 00:00:00 2001 From: Tom Wanzek Date: Sat, 20 Aug 2016 14:53:42 -0400 Subject: [PATCH] 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. --- d3-shape/index.d.ts | 4 +++- d3-voronoi/d3-voronoi-tests.ts | 10 ++++++++++ d3-voronoi/index.d.ts | 16 +++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/d3-shape/index.d.ts b/d3-shape/index.d.ts index 01a2302bf9..cf3f0a5c21 100644 --- a/d3-shape/index.d.ts +++ b/d3-shape/index.d.ts @@ -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 extends Array { + 0: number; + 1: number; index: number; data: Datum; } diff --git a/d3-voronoi/d3-voronoi-tests.ts b/d3-voronoi/d3-voronoi-tests.ts index 87617519c3..2255d75b74 100644 --- a/d3-voronoi/d3-voronoi-tests.ts +++ b/d3-voronoi/d3-voronoi-tests.ts @@ -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; diff --git a/d3-voronoi/index.d.ts b/d3-voronoi/index.d.ts index e16a780c82..0265019451 100644 --- a/d3-voronoi/index.d.ts +++ b/d3-voronoi/index.d.ts @@ -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; +export interface VoronoiPoint extends Array { + 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 extends Array<[number, number]> { data: T;