D3 geo strict null check (#23794)

* d3-geo strictNullChecks mode:
Allow GeoGeometryObjects type to be null
Check existence of optional mehtods before calling them
Added null to union type or some results of call

* Missing space

* Min TS 2.4 for d3-geo

* Back to TS 2.3

* Added null as acceptable type

* d3-geo : Use of default generic types

* d3-geo : Removed generic type when using default

* d3-geo : fix generic types

* d3-geo : tests with nullable features
This commit is contained in:
Hugues Stefanski 2018-04-14 21:37:38 +02:00 committed by Mohamed Hegazy
parent 4ac43f6061
commit 65622d3c46
3 changed files with 175 additions and 61 deletions

View File

@ -89,7 +89,33 @@ const sampleExtendedFeatureCollection: d3Geo.ExtendedFeatureCollection<d3Geo.Ext
sampleExtendedFeature2
]
};
const sampleNullableFeature: GeoJSON.Feature<null> = {
type: 'Feature',
geometry: null,
properties: null
};
const sampleExtendedNullableFeature: d3Geo.ExtendedFeature = {
type: 'Feature',
geometry: null,
properties: null
};
const sampleNullableFeatureCollection: GeoJSON.FeatureCollection<null> = {
type: 'FeatureCollection',
features: [
sampleNullableFeature,
sampleNullableFeature
]
};
const sampleExtendedNullableFeatureCollection: d3Geo.ExtendedFeatureCollection = {
type: 'FeatureCollection',
features: [
sampleExtendedNullableFeature,
sampleExtendedNullableFeature
]
};
// ----------------------------------------------------------------------
// Spherical Math
// ----------------------------------------------------------------------
@ -101,10 +127,14 @@ area = d3Geo.geoArea(sampleSphere);
area = d3Geo.geoArea(sampleGeometryCollection);
area = d3Geo.geoArea(sampleExtendedGeometryCollection);
area = d3Geo.geoArea(sampleFeature);
area = d3Geo.geoArea(sampleNullableFeature);
area = d3Geo.geoArea(sampleExtendedFeature1);
area = d3Geo.geoArea(sampleExtendedFeature2);
area = d3Geo.geoArea(sampleExtendedNullableFeature);
area = d3Geo.geoArea(sampleFeatureCollection);
area = d3Geo.geoArea(sampleNullableFeatureCollection);
area = d3Geo.geoArea(sampleExtendedFeatureCollection);
area = d3Geo.geoArea(sampleExtendedNullableFeatureCollection);
// geoBounds(...) =========================================================
@ -113,10 +143,14 @@ bounds = d3Geo.geoBounds(sampleSphere);
bounds = d3Geo.geoBounds(sampleGeometryCollection);
bounds = d3Geo.geoBounds(sampleExtendedGeometryCollection);
bounds = d3Geo.geoBounds(sampleFeature);
bounds = d3Geo.geoBounds(sampleNullableFeature);
bounds = d3Geo.geoBounds(sampleExtendedFeature1);
bounds = d3Geo.geoBounds(sampleExtendedFeature2);
bounds = d3Geo.geoBounds(sampleExtendedNullableFeature);
bounds = d3Geo.geoBounds(sampleFeatureCollection);
bounds = d3Geo.geoBounds(sampleNullableFeatureCollection);
bounds = d3Geo.geoBounds(sampleExtendedFeatureCollection);
bounds = d3Geo.geoBounds(sampleExtendedNullableFeatureCollection);
// geoCentroid(...) =======================================================
@ -125,10 +159,14 @@ centroid = d3Geo.geoCentroid(sampleSphere);
centroid = d3Geo.geoCentroid(sampleGeometryCollection);
centroid = d3Geo.geoCentroid(sampleExtendedGeometryCollection);
centroid = d3Geo.geoCentroid(sampleFeature);
centroid = d3Geo.geoCentroid(sampleNullableFeature);
centroid = d3Geo.geoCentroid(sampleExtendedFeature1);
centroid = d3Geo.geoCentroid(sampleExtendedFeature2);
centroid = d3Geo.geoCentroid(sampleExtendedNullableFeature);
centroid = d3Geo.geoCentroid(sampleFeatureCollection);
centroid = d3Geo.geoCentroid(sampleNullableFeatureCollection);
centroid = d3Geo.geoCentroid(sampleExtendedFeatureCollection);
centroid = d3Geo.geoCentroid(sampleExtendedNullableFeatureCollection);
// geoContains(...) =======================================================
@ -137,10 +175,14 @@ contained = d3Geo.geoContains(sampleSphere, [0, 0]);
contained = d3Geo.geoContains(sampleGeometryCollection, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedGeometryCollection, [0, 0]);
contained = d3Geo.geoContains(sampleFeature, [0, 0]);
contained = d3Geo.geoContains(sampleNullableFeature, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedFeature1, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedFeature2, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedNullableFeature, [0, 0]);
contained = d3Geo.geoContains(sampleFeatureCollection, [0, 0]);
contained = d3Geo.geoContains(sampleNullableFeatureCollection, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedFeatureCollection, [0, 0]);
contained = d3Geo.geoContains(sampleExtendedNullableFeatureCollection, [0, 0]);
// geoDistance(...) =======================================================
@ -153,10 +195,14 @@ length = d3Geo.geoLength(sampleSphere);
length = d3Geo.geoLength(sampleGeometryCollection);
length = d3Geo.geoLength(sampleExtendedGeometryCollection);
length = d3Geo.geoLength(sampleFeature);
length = d3Geo.geoLength(sampleNullableFeature);
length = d3Geo.geoLength(sampleExtendedFeature1);
length = d3Geo.geoLength(sampleExtendedFeature2);
length = d3Geo.geoLength(sampleExtendedNullableFeature);
length = d3Geo.geoLength(sampleFeatureCollection);
length = d3Geo.geoLength(sampleNullableFeatureCollection);
length = d3Geo.geoLength(sampleExtendedFeatureCollection);
length = d3Geo.geoLength(sampleExtendedNullableFeatureCollection);
// geoInterpolate(...) ====================================================
@ -181,7 +227,7 @@ const inverted: [number, number] = rotation.invert([54, 2]);
// Create GeoCircleGenerator ============================================
// simple use case
let circleGeneratorSimple: d3Geo.GeoCircleGenerator<any, any> = d3Geo.geoCircle();
let circleGeneratorSimple: d3Geo.GeoCircleGenerator = d3Geo.geoCircle();
// complex use as part of object
class Circulator {
@ -331,8 +377,9 @@ const naturalEart1Raw: d3Geo.GeoRawProjection = d3Geo.geoNaturalEarth1Raw();
// Use Raw Projection =====================================================
const rawProjectionPoint: [number, number] = azimuthalEqualAreaRaw(54, 2);
const rawProjectionInvertedPoint: [number, number] = azimuthalEqualAreaRaw.invert(180, 6);
if (azimuthalEqualAreaRaw.invert) {
const rawProjectionInvertedPoint: [number, number] = azimuthalEqualAreaRaw.invert(180, 6);
}
// ----------------------------------------------------------------------
// Pre-Defined Projections
// ----------------------------------------------------------------------
@ -365,8 +412,10 @@ let constructedProjection: d3Geo.GeoProjection = mutate();
// Use Projection ==========================================================
const projected: [number, number] = constructedProjection([54, 2]);
const inverted2: [number, number] = constructedProjection.invert([54, 2]);
const projected: [number, number] | null = constructedProjection([54, 2]);
if (constructedProjection.invert) {
const inverted2: [number, number] | null = constructedProjection.invert([54, 2]);
}
// TODO ?????
// let stream: d3Geo.Stream = constructedProjection.stream([54, 2]);
@ -378,7 +427,7 @@ constructedProjection = constructedProjection.preclip(d3Geo.geoClipCircle(45));
const postClip: (stream: d3Geo.GeoStream) => d3Geo.GeoStream = constructedProjection.postclip();
constructedProjection = constructedProjection.postclip(d3Geo.geoClipRectangle(0, 0, 1, 1));
const clipAngle: number = constructedProjection.clipAngle();
const clipAngle: number | null = constructedProjection.clipAngle();
constructedProjection = constructedProjection.clipAngle(null);
constructedProjection = constructedProjection.clipAngle(45);
@ -410,40 +459,56 @@ constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sa
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleGeometryCollection);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedGeometryCollection);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleFeature);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleNullableFeature);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedFeature1);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedFeature2);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedNullableFeature);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleFeatureCollection);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleNullableFeatureCollection);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedFeatureCollection);
constructedProjection = constructedProjection.fitExtent([[0, 0], [960, 500]], sampleExtendedNullableFeatureCollection);
constructedProjection = constructedProjection.fitSize([960, 500], samplePolygon);
constructedProjection = constructedProjection.fitSize([960, 500], sampleSphere);
constructedProjection = constructedProjection.fitSize([960, 500], sampleGeometryCollection);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedGeometryCollection);
constructedProjection = constructedProjection.fitSize([960, 500], sampleFeature);
constructedProjection = constructedProjection.fitSize([960, 500], sampleNullableFeature);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedFeature1);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedFeature2);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedNullableFeature);
constructedProjection = constructedProjection.fitSize([960, 500], sampleFeatureCollection);
constructedProjection = constructedProjection.fitSize([960, 500], sampleNullableFeatureCollection);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedFeatureCollection);
constructedProjection = constructedProjection.fitSize([960, 500], sampleExtendedNullableFeatureCollection);
constructedProjection = constructedProjection.fitWidth(960, samplePolygon);
constructedProjection = constructedProjection.fitWidth(960, sampleSphere);
constructedProjection = constructedProjection.fitWidth(960, sampleGeometryCollection);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedGeometryCollection);
constructedProjection = constructedProjection.fitWidth(960, sampleFeature);
constructedProjection = constructedProjection.fitWidth(960, sampleNullableFeature);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedFeature1);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedFeature2);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedNullableFeature);
constructedProjection = constructedProjection.fitWidth(960, sampleFeatureCollection);
constructedProjection = constructedProjection.fitWidth(960, sampleNullableFeatureCollection);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedFeatureCollection);
constructedProjection = constructedProjection.fitWidth(960, sampleExtendedNullableFeatureCollection);
constructedProjection = constructedProjection.fitHeight(500, samplePolygon);
constructedProjection = constructedProjection.fitHeight(500, sampleSphere);
constructedProjection = constructedProjection.fitHeight(500, sampleGeometryCollection);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedGeometryCollection);
constructedProjection = constructedProjection.fitHeight(500, sampleFeature);
constructedProjection = constructedProjection.fitHeight(500, sampleNullableFeature);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedFeature1);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedFeature2);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedNullableFeature);
constructedProjection = constructedProjection.fitHeight(500, sampleFeatureCollection);
constructedProjection = constructedProjection.fitHeight(500, sampleNullableFeatureCollection);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedFeatureCollection);
constructedProjection = constructedProjection.fitHeight(500, sampleExtendedNullableFeatureCollection);
// ----------------------------------------------------------------------
// GeoConicProjection interface
@ -471,7 +536,7 @@ const minimalRenderingContextMockUp: d3Geo.GeoContext = {
// Create geoPath Generator =============================================
let geoPathCanvas: d3Geo.GeoPath<any, d3Geo.GeoPermissibleObjects>;
let geoPathCanvas: d3Geo.GeoPath;
geoPathCanvas = d3Geo.geoPath();
geoPathCanvas = d3Geo.geoPath(null);
geoPathCanvas = d3Geo.geoPath(null, null);
@ -487,8 +552,8 @@ geoPathSVG = d3Geo.geoPath<SVGPathElement, d3Geo.ExtendedFeature<GeoJSON.Polygon
// projection(...) ------------------------------------------------------
geoPathCanvas = geoPathCanvas.projection(azimuthalEqualArea);
const geoPathProjectionMinimal: d3Geo.GeoStreamWrapper = geoPathCanvas.projection();
const geoPathProjectionUnion: d3Geo.GeoProjection | d3Geo.GeoConicProjection | d3Geo.GeoStreamWrapper = geoPathCanvas.projection();
const geoPathProjectionMinimal: d3Geo.GeoStreamWrapper | null = geoPathCanvas.projection();
const geoPathProjectionUnion: d3Geo.GeoProjection | d3Geo.GeoConicProjection | d3Geo.GeoStreamWrapper | null = geoPathCanvas.projection();
const geoPathProjection: d3Geo.GeoProjection = geoPathCanvas.projection<d3Geo.GeoProjection>();
geoPathSVG = geoPathSVG.projection(conicConformal);
@ -501,13 +566,13 @@ const geoPathConicProjection: d3Geo.GeoConicProjection = geoPathSVG.projection<d
// minimal context interface (mockup)
geoPathCanvas = geoPathCanvas.context(minimalRenderingContextMockUp);
const geoPathContext: d3Geo.GeoContext = geoPathCanvas.context();
const geoPathContext: d3Geo.GeoContext | null = geoPathCanvas.context();
// reset
geoPathCanvas = geoPathCanvas.context(null);
// With canvas 2D rendering context
let canvasContext: CanvasRenderingContext2D;
let canvasContext: CanvasRenderingContext2D = {} as any;
geoPathCanvas = geoPathCanvas.context(canvasContext);
@ -540,12 +605,17 @@ geoPathArea = geoPathCanvas.area(sampleSphere);
geoPathArea = geoPathCanvas.area(sampleGeometryCollection);
geoPathArea = geoPathCanvas.area(sampleExtendedGeometryCollection);
geoPathArea = geoPathCanvas.area(sampleFeature);
geoPathArea = geoPathCanvas.area(sampleNullableFeature);
geoPathArea = geoPathCanvas.area(sampleExtendedFeature1);
geoPathArea = geoPathCanvas.area(sampleExtendedFeature2);
geoPathArea = geoPathCanvas.area(sampleExtendedNullableFeature);
geoPathArea = geoPathCanvas.area(sampleFeatureCollection);
geoPathArea = geoPathCanvas.area(sampleNullableFeatureCollection);
geoPathArea = geoPathCanvas.area(sampleExtendedFeatureCollection);
geoPathArea = geoPathCanvas.area(sampleExtendedNullableFeatureCollection);
// geoPathArea = geoPathSVG.area(sampleExtendedFeatureCollection); // fails, wrong data object type
// geoPathArea = geoPathSVG.area(sampleExtendedNullableFeatureCollection); // fails, wrong data object type
// bounds(...) ------------------------------------------------------
@ -554,12 +624,17 @@ geoPathBounds = geoPathCanvas.bounds(sampleSphere);
geoPathBounds = geoPathCanvas.bounds(sampleGeometryCollection);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedGeometryCollection);
geoPathBounds = geoPathCanvas.bounds(sampleFeature);
geoPathBounds = geoPathCanvas.bounds(sampleNullableFeature);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedFeature1);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedFeature2);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedNullableFeature);
geoPathBounds = geoPathCanvas.bounds(sampleFeatureCollection);
geoPathBounds = geoPathCanvas.bounds(sampleNullableFeatureCollection);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedFeatureCollection);
geoPathBounds = geoPathCanvas.bounds(sampleExtendedNullableFeatureCollection);
// geoPathBounds = geoPathSVG.bounds(sampleExtendedFeatureCollection); // fails, wrong data object type
// geoPathBounds = geoPathSVG.bounds(sampleExtendedNullableFeatureCollection); // fails, wrong data object type
// centroid(...) ------------------------------------------------------
@ -568,12 +643,17 @@ geoPathCentroid = geoPathCanvas.centroid(sampleSphere);
geoPathCentroid = geoPathCanvas.centroid(sampleGeometryCollection);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedGeometryCollection);
geoPathCentroid = geoPathCanvas.centroid(sampleFeature);
geoPathCentroid = geoPathCanvas.centroid(sampleNullableFeature);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedFeature1);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedFeature2);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedNullableFeature);
geoPathCentroid = geoPathCanvas.centroid(sampleFeatureCollection);
geoPathCentroid = geoPathCanvas.centroid(sampleNullableFeatureCollection);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedFeatureCollection);
geoPathCentroid = geoPathCanvas.centroid(sampleExtendedNullableFeatureCollection);
// geoPathCentroid = geoPathSVG.centroid(sampleExtendedFeatureCollection); // fails, wrong data object type
// geoPathCentroid = geoPathSVG.centroid(sampleExtendedNullableFeatureCollection); // fails, wrong data object type
// measure(...) ------------------------------------------------------
@ -582,10 +662,14 @@ geoPathMeasure = geoPathCanvas.measure(sampleSphere);
geoPathMeasure = geoPathCanvas.measure(sampleGeometryCollection);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedGeometryCollection);
geoPathMeasure = geoPathCanvas.measure(sampleFeature);
geoPathMeasure = geoPathCanvas.measure(sampleNullableFeature);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedFeature1);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedFeature2);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedNullableFeature);
geoPathMeasure = geoPathCanvas.measure(sampleFeatureCollection);
geoPathMeasure = geoPathCanvas.measure(sampleNullableFeatureCollection);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedFeatureCollection);
geoPathMeasure = geoPathCanvas.measure(sampleExtendedNullableFeatureCollection);
// render path to context of get path string----------------------------
@ -596,10 +680,14 @@ geoPathCanvas(sampleSphere);
geoPathCanvas(sampleGeometryCollection);
geoPathCanvas(sampleExtendedGeometryCollection);
geoPathCanvas(sampleFeature);
geoPathCanvas(sampleNullableFeature);
geoPathCanvas(sampleExtendedFeature1);
geoPathCanvas(sampleExtendedFeature2);
geoPathCanvas(sampleExtendedNullableFeature);
geoPathCanvas(sampleFeatureCollection);
geoPathCanvas(sampleNullableFeatureCollection);
geoPathCanvas(sampleExtendedFeatureCollection);
geoPathCanvas(sampleExtendedNullableFeatureCollection);
// Use path string generator for SVGPathElement
@ -667,20 +755,28 @@ identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleSphe
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleGeometryCollection);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedGeometryCollection);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleFeature);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleNullableFeature);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedFeature1);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedFeature2);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedNullableFeature);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleFeatureCollection);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleNullableFeatureCollection);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedFeatureCollection);
identityTransform = identityTransform.fitExtent([[0, 0], [960, 500]], sampleExtendedNullableFeatureCollection);
identityTransform = identityTransform.fitSize([960, 500], samplePolygon);
identityTransform = identityTransform.fitSize([960, 500], sampleSphere);
identityTransform = identityTransform.fitSize([960, 500], sampleGeometryCollection);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedGeometryCollection);
identityTransform = identityTransform.fitSize([960, 500], sampleFeature);
identityTransform = identityTransform.fitSize([960, 500], sampleNullableFeature);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedFeature1);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedFeature2);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedNullableFeature);
identityTransform = identityTransform.fitSize([960, 500], sampleFeatureCollection);
identityTransform = identityTransform.fitSize([960, 500], sampleNullableFeatureCollection);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedFeatureCollection);
identityTransform = identityTransform.fitSize([960, 500], sampleExtendedNullableFeatureCollection);
let reflecting: boolean;
@ -703,7 +799,9 @@ stream.lineStart();
stream.lineEnd();
stream.polygonStart();
stream.polygonEnd();
stream.sphere();
if (stream.sphere) {
stream.sphere();
}
// geoStream(...) ========================================================
@ -712,10 +810,14 @@ d3Geo.geoStream(sampleSphere, stream);
d3Geo.geoStream(sampleGeometryCollection, stream);
d3Geo.geoStream(sampleExtendedGeometryCollection, stream);
d3Geo.geoStream(sampleFeature, stream);
d3Geo.geoStream(sampleNullableFeature, stream);
d3Geo.geoStream(sampleExtendedFeature1, stream);
d3Geo.geoStream(sampleExtendedFeature2, stream);
d3Geo.geoStream(sampleExtendedNullableFeature, stream);
d3Geo.geoStream(sampleFeatureCollection, stream);
d3Geo.geoStream(sampleNullableFeatureCollection, stream);
d3Geo.geoStream(sampleExtendedFeatureCollection, stream);
d3Geo.geoStream(sampleExtendedNullableFeatureCollection, stream);
// ----------------------------------------------------------------------
// Clipping Function

View File

@ -31,9 +31,11 @@ export type GeoGeometryObjects = GeoJSON.GeometryObject | GeoSphere;
/**
* A GeoJSON-style GeometryCollection which supports GeoJSON geometry objects
* and additionally GeoSphere
* and additionally GeoSphere.
*
* The generic refers to the type(s) of d3-geo geometry objects contained in the collection.
*/
export interface ExtendedGeometryCollection<GeometryType extends GeoGeometryObjects> {
export interface ExtendedGeometryCollection<GeometryType extends GeoGeometryObjects = GeoGeometryObjects> {
type: string;
bbox?: number[];
crs?: {
@ -45,9 +47,18 @@ export interface ExtendedGeometryCollection<GeometryType extends GeoGeometryObje
/**
* A GeoJSON-style Feature which support features built on GeoJSON GeometryObjects
* or GeoSphere
* or GeoSphere.
*
* The first generic refers to the type(s) of d3-geo geometry objects underlying the ExtendedFeature.
* Unless explicitly ruled out, the geometry value is nullable.
*
* The second generic refers to the data type of the properties of the ExtendedFeature. Unless explicitly ruled out,
* the properties value is nullable.
*/
export interface ExtendedFeature<GeometryType extends GeoGeometryObjects, Properties> extends GeoJSON.GeoJsonObject {
export interface ExtendedFeature<
GeometryType extends GeoGeometryObjects | null = GeoGeometryObjects | null,
Properties extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties
> extends GeoJSON.GeoJsonObject {
geometry: GeometryType;
properties: Properties;
id?: string | number;
@ -56,8 +67,10 @@ export interface ExtendedFeature<GeometryType extends GeoGeometryObjects, Proper
/**
* A GeoJSON-style FeatureCollection which supports GeoJSON features
* and features built on GeoSphere
*
* The generic refers to the type of ExtendedFeature contained in the ExtendedFeatureCollection.
*/
export interface ExtendedFeatureCollection<FeatureType extends ExtendedFeature<GeoGeometryObjects, any>> extends GeoJSON.GeoJsonObject {
export interface ExtendedFeatureCollection<FeatureType extends ExtendedFeature = ExtendedFeature> extends GeoJSON.GeoJsonObject {
features: FeatureType[];
}
@ -65,8 +78,7 @@ export interface ExtendedFeatureCollection<FeatureType extends ExtendedFeature<G
* Type Alias for permissible objects which can be used with d3-geo
* methods
*/
export type GeoPermissibleObjects = GeoGeometryObjects | ExtendedGeometryCollection<GeoGeometryObjects>
| ExtendedFeature<GeoGeometryObjects, any> | ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>;
export type GeoPermissibleObjects = GeoGeometryObjects | ExtendedGeometryCollection | ExtendedFeature | ExtendedFeatureCollection;
// ----------------------------------------------------------------------
// Spherical Math
@ -78,14 +90,14 @@ export type GeoPermissibleObjects = GeoGeometryObjects | ExtendedGeometryCollect
*
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoArea(object: ExtendedFeature<GeoGeometryObjects, any>): number;
export function geoArea(object: ExtendedFeature): number;
/**
* Returns the spherical area of the specified feature collection in steradians.
* This is the spherical equivalent of path.area.
*
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoArea(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): number;
export function geoArea(object: ExtendedFeatureCollection): number;
/**
* Returns the spherical area of the specified GeoJson Geometry Object or GeoSphere object in steradians.
* This is the spherical equivalent of path.area.
@ -99,7 +111,7 @@ export function geoArea(object: GeoGeometryObjects): number;
*
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
export function geoArea(object: ExtendedGeometryCollection<GeoGeometryObjects>): number;
export function geoArea(object: ExtendedGeometryCollection): number;
/**
* Returns the spherical bounding box for the specified feature. The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]],
@ -109,7 +121,7 @@ export function geoArea(object: ExtendedGeometryCollection<GeoGeometryObjects>):
*
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoBounds(object: ExtendedFeature<GeoGeometryObjects, any>): [[number, number], [number, number]];
export function geoBounds(object: ExtendedFeature): [[number, number], [number, number]];
/**
* Returns the spherical bounding box for the specified feature collection. The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]],
* where left is the minimum longitude, bottom is the minimum latitude, right is maximum longitude, and top is the maximum latitude. All coordinates are given in degrees.
@ -118,7 +130,7 @@ export function geoBounds(object: ExtendedFeature<GeoGeometryObjects, any>): [[n
*
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoBounds(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): [[number, number], [number, number]];
export function geoBounds(object: ExtendedFeatureCollection): [[number, number], [number, number]];
/**
* Returns the spherical bounding box for the specified GeoJson Geometry Object or GeoSphere object. The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]],
* where left is the minimum longitude, bottom is the minimum latitude, right is maximum longitude, and top is the maximum latitude. All coordinates are given in degrees.
@ -136,7 +148,7 @@ export function geoBounds(object: GeoGeometryObjects): [[number, number], [numbe
*
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
export function geoBounds(object: ExtendedGeometryCollection<GeoGeometryObjects>): [[number, number], [number, number]];
export function geoBounds(object: ExtendedGeometryCollection): [[number, number], [number, number]];
/**
* Returns the spherical centroid of the specified feature in steradians.
@ -144,14 +156,14 @@ export function geoBounds(object: ExtendedGeometryCollection<GeoGeometryObjects>
*
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoCentroid(object: ExtendedFeature<GeoGeometryObjects, any>): [number, number];
export function geoCentroid(object: ExtendedFeature): [number, number];
/**
* Returns the spherical centroid of the specified feature collection in steradians.
* This is the spherical equivalent of path.centroid.
*
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoCentroid(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): [number, number];
export function geoCentroid(object: ExtendedFeatureCollection): [number, number];
/**
* Returns the spherical centroid of the specified GeoJson Geometry Object or GeoSphere object in steradians.
* This is the spherical equivalent of path.centroid.
@ -165,7 +177,7 @@ export function geoCentroid(object: GeoGeometryObjects): [number, number];
*
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
export function geoCentroid(object: ExtendedGeometryCollection<GeoGeometryObjects>): [number, number];
export function geoCentroid(object: ExtendedGeometryCollection): [number, number];
/**
* Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point.
@ -175,7 +187,7 @@ export function geoCentroid(object: ExtendedGeometryCollection<GeoGeometryObject
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
* @param point Point specified as a two-element array [longitude, latitude] in degrees.
*/
export function geoContains(object: ExtendedFeature<GeoGeometryObjects, any>, point: [number, number]): boolean;
export function geoContains(object: ExtendedFeature, point: [number, number]): boolean;
/**
* Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point.
* The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used;
@ -184,7 +196,7 @@ export function geoContains(object: ExtendedFeature<GeoGeometryObjects, any>, po
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
* @param point Point specified as a two-element array [longitude, latitude] in degrees.
*/
export function geoContains(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>, point: [number, number]): boolean;
export function geoContains(object: ExtendedFeatureCollection, point: [number, number]): boolean;
/**
* Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point.
* The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used;
@ -202,7 +214,7 @@ export function geoContains(object: GeoGeometryObjects, point: [number, number])
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
* @param point Point specified as a two-element array [longitude, latitude] in degrees.
*/
export function geoContains(object: ExtendedGeometryCollection<GeoGeometryObjects>, point: [number, number]): boolean;
export function geoContains(object: ExtendedGeometryCollection, point: [number, number]): boolean;
/**
* Returns the great-arc distance in radians between the two points a and b.
@ -219,14 +231,14 @@ export function geoDistance(a: [number, number], b: [number, number]): number;
*
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoLength(object: ExtendedFeature<GeoGeometryObjects, any>): number;
export function geoLength(object: ExtendedFeature): number;
/**
* Returns the great-arc length of the specified feature collection in radians. For polygons, returns the perimeter of the exterior ring plus that of any interior rings.
* This is the spherical equivalent of path.measure.
*
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
*/
export function geoLength(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): number;
export function geoLength(object: ExtendedFeatureCollection): number;
/**
* Returns the great-arc length of the specified GeoJson Geometry Object or GeoSphere object in radians. For polygons, returns the perimeter of the exterior ring plus that of any interior rings.
* This is the spherical equivalent of path.measure.
@ -240,7 +252,7 @@ export function geoLength(object: GeoGeometryObjects): number;
*
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
export function geoLength(object: ExtendedGeometryCollection<GeoGeometryObjects>): number;
export function geoLength(object: ExtendedGeometryCollection): number;
/**
* Returns an interpolator function given two points a and b.
@ -291,7 +303,7 @@ export function geoRotation(angles: [number, number] | [number, number, number])
*
* The second generic corresponds to the type of the Datum which will be passed into the geo circle generator.
*/
export interface GeoCircleGenerator<This, Datum> {
export interface GeoCircleGenerator<This = any, Datum = any> {
/**
* Returns a new GeoJSON geometry object of type Polygon approximating a circle on the surface of a sphere,
* with the current center, radius and precision. Any arguments are passed to the accessors.
@ -362,7 +374,7 @@ export interface GeoCircleGenerator<This, Datum> {
/**
* Returns a new geo circle generator
*/
export function geoCircle(): GeoCircleGenerator<any, any>;
export function geoCircle(): GeoCircleGenerator;
/**
* Returns a new geo circle generator
*
@ -547,7 +559,7 @@ export interface GeoStream {
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
* @param stream A projection stream.
*/
export function geoStream(object: ExtendedFeature<GeoGeometryObjects, any>, stream: GeoStream): void;
export function geoStream(object: ExtendedFeature, stream: GeoStream): void;
/**
* Streams the specified GeoJSON object to the specified projection stream. While both features and geometry objects are supported as input,
@ -556,7 +568,7 @@ export function geoStream(object: ExtendedFeature<GeoGeometryObjects, any>, stre
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature).
* @param stream A projection stream.
*/
export function geoStream(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>, stream: GeoStream): void;
export function geoStream(object: ExtendedFeatureCollection, stream: GeoStream): void;
/**
* Streams the specified GeoJSON object to the specified projection stream. While both features and geometry objects are supported as input,
@ -574,7 +586,7 @@ export function geoStream(object: GeoGeometryObjects, stream: GeoStream): void;
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
* @param stream A projection stream.
*/
export function geoStream(object: ExtendedGeometryCollection<GeoGeometryObjects>, stream: GeoStream): void;
export function geoStream(object: ExtendedGeometryCollection, stream: GeoStream): void;
// ----------------------------------------------------------------------
// Projections
@ -736,7 +748,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature collection in the center of the given extent.
* Returns the projection.
@ -746,7 +758,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature collection).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic geometry object in the center of the given extent.
* Returns the projection.
@ -766,7 +778,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature in the center of an extent with the given size and top-left corner of [0, 0].
@ -777,7 +789,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitSize(size: [number, number], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitSize(size: [number, number], object: ExtendedFeature): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature collection in the center of an extent with the given size and top-left corner of [0, 0].
* Returns the projection.
@ -787,7 +799,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature collection).
*/
fitSize(size: [number, number], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitSize(size: [number, number], object: ExtendedFeatureCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic geometry object in the center of an extent with the given size and top-left corner of [0, 0].
* Returns the projection.
@ -807,7 +819,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitSize(size: [number, number], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitSize(size: [number, number], object: ExtendedGeometryCollection): this;
/**
* A convenience method for projection.fitSize where the height is automatically chosen from the aspect ratio of object and the given constraint on width.
@ -815,14 +827,14 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param width The width of the extent.
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitWidth(width: number, object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitWidth(width: number, object: ExtendedFeature): this;
/**
* A convenience method for projection.fitSize where the height is automatically chosen from the aspect ratio of object and the given constraint on width.
*
* @param width The width of the extent.
* @param object A GeoJson Geometry Object or GeoSphere object supported by d3-geo (An extension of GeoJSON).
*/
fitWidth(width: number, object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitWidth(width: number, object: ExtendedFeatureCollection): this;
/**
* A convenience method for projection.fitSize where the height is automatically chosen from the aspect ratio of object and the given constraint on width.
*
@ -836,7 +848,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param width The width of the extent.
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitWidth(width: number, object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitWidth(width: number, object: ExtendedGeometryCollection): this;
/**
* A convenience method for projection.fitSize where the width is automatically chosen from the aspect ratio of object and the given constraint on height.
@ -844,14 +856,14 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param height The height of the extent.
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitHeight(height: number, object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitHeight(height: number, object: ExtendedFeature): this;
/**
* A convenience method for projection.fitSize where the width is automatically chosen from the aspect ratio of object and the given constraint on height.
*
* @param height The height of the extent.
* @param object A GeoJson Geometry Object or GeoSphere object supported by d3-geo (An extension of GeoJSON).
*/
fitHeight(height: number, object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitHeight(height: number, object: ExtendedFeatureCollection): this;
/**
* A convenience method for projection.fitSize where the width is automatically chosen from the aspect ratio of object and the given constraint on height.
*
@ -865,7 +877,7 @@ export interface GeoProjection extends GeoStreamWrapper {
* @param height The height of the extent.
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitHeight(height: number, object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitHeight(height: number, object: ExtendedGeometryCollection): this;
/**
* Returns a new array [longitude, latitude] in degrees representing the unprojected point of the given projected point.
@ -1012,7 +1024,7 @@ export interface GeoContext {
*
* The second generic corresponds to the type of the DatumObject which will be passed into the geo path generator for rendering.
*/
export interface GeoPath<This, DatumObject extends GeoPermissibleObjects> {
export interface GeoPath<This = any, DatumObject extends GeoPermissibleObjects = GeoPermissibleObjects> {
/**
* Renders the given object, which may be any GeoJSON feature or geometry object:
*
@ -1222,7 +1234,7 @@ export interface GeoPath<This, DatumObject extends GeoPermissibleObjects> {
* @param context An (optional) rendering context to be used. If a context is provided, it must at least implement the interface described by GeoContext, a subset of the CanvasRenderingContext2D API.
* Setting the context to "null" means that the path generator will return an SVG path string representing the to be rendered object. The default is "null".
*/
export function geoPath(projection?: GeoProjection | GeoStreamWrapper | null, context?: GeoContext | null): GeoPath<any, GeoPermissibleObjects>;
export function geoPath(projection?: GeoProjection | GeoStreamWrapper | null, context?: GeoContext | null): GeoPath;
/**
* Creates a new geographic path generator with the default settings.
*
@ -1525,7 +1537,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature collection in the center of the given extent.
* Returns the projection.
@ -1535,7 +1547,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature collection).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic geometry object in the center of the given extent.
* Returns the projection.
@ -1555,7 +1567,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param extent The extent, specified as an array [[x, y], [x, y]], where x is the left side of the bounding box, y is the top, x is the right and y is the bottom.
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature in the center of an extent with the given size and top-left corner of [0, 0].
@ -1566,7 +1578,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature).
*/
fitSize(size: [number, number], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitSize(size: [number, number], object: ExtendedFeature): this;
/**
* Sets the projections scale and translate to fit the specified geographic feature collection in the center of an extent with the given size and top-left corner of [0, 0].
* Returns the projection.
@ -1576,7 +1588,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature collection).
*/
fitSize(size: [number, number], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitSize(size: [number, number], object: ExtendedFeatureCollection): this;
/**
* Sets the projections scale and translate to fit the specified geographic geometry object in the center of an extent with the given size and top-left corner of [0, 0].
* Returns the projection.
@ -1596,7 +1608,7 @@ export interface GeoIdentityTranform extends GeoStreamWrapper {
* @param size The size of the extent, specified as an array [width, height].
* @param object A geographic geometry collection supported by d3-geo (An extension of GeoJSON geometry collection).
*/
fitSize(size: [number, number], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
fitSize(size: [number, number], object: ExtendedGeometryCollection): this;
/**
* Returns true if x-reflection is enabled, which defaults to false.

View File

@ -7,7 +7,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@ -21,4 +21,4 @@
"index.d.ts",
"d3-geo-tests.ts"
]
}
}