From 65622d3c46c36be7d5fbb32633026fce6b391384 Mon Sep 17 00:00:00 2001 From: Hugues Stefanski Date: Sat, 14 Apr 2018 21:37:38 +0200 Subject: [PATCH] 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 --- types/d3-geo/d3-geo-tests.ts | 126 +++++++++++++++++++++++++++++++---- types/d3-geo/index.d.ts | 106 ++++++++++++++++------------- types/d3-geo/tsconfig.json | 4 +- 3 files changed, 175 insertions(+), 61 deletions(-) diff --git a/types/d3-geo/d3-geo-tests.ts b/types/d3-geo/d3-geo-tests.ts index 5124694378..51ddb93d89 100644 --- a/types/d3-geo/d3-geo-tests.ts +++ b/types/d3-geo/d3-geo-tests.ts @@ -89,7 +89,33 @@ const sampleExtendedFeatureCollection: d3Geo.ExtendedFeatureCollection = { + type: 'Feature', + geometry: null, + properties: null +}; +const sampleExtendedNullableFeature: d3Geo.ExtendedFeature = { + type: 'Feature', + geometry: null, + properties: null +}; + +const sampleNullableFeatureCollection: GeoJSON.FeatureCollection = { + 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 = 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; +let geoPathCanvas: d3Geo.GeoPath; geoPathCanvas = d3Geo.geoPath(); geoPathCanvas = d3Geo.geoPath(null); geoPathCanvas = d3Geo.geoPath(null, null); @@ -487,8 +552,8 @@ geoPathSVG = d3Geo.geoPath(); geoPathSVG = geoPathSVG.projection(conicConformal); @@ -501,13 +566,13 @@ const geoPathConicProjection: d3Geo.GeoConicProjection = geoPathSVG.projection { +export interface ExtendedGeometryCollection { type: string; bbox?: number[]; crs?: { @@ -45,9 +47,18 @@ export interface ExtendedGeometryCollection 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> extends GeoJSON.GeoJsonObject { +export interface ExtendedFeatureCollection extends GeoJSON.GeoJsonObject { features: FeatureType[]; } @@ -65,8 +78,7 @@ export interface ExtendedFeatureCollection - | ExtendedFeature | ExtendedFeatureCollection>; +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): 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>): 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): 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): * * @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature). */ -export function geoBounds(object: ExtendedFeature): [[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): [[n * * @param object A geographic feature collection supported by d3-geo (An extension of GeoJSON feature). */ -export function geoBounds(object: ExtendedFeatureCollection>): [[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): [[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 * * @param object A geographic feature supported by d3-geo (An extension of GeoJSON feature). */ -export function geoCentroid(object: ExtendedFeature): [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>): [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): [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, 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, 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>, 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, 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): 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>): 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): 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 { +export interface GeoCircleGenerator { /** * 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 { /** * Returns a new geo circle generator */ -export function geoCircle(): GeoCircleGenerator; +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, 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, 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>, 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, 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): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature): this; /** * Sets the projection’s 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>): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection): this; /** * Sets the projection’s 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): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection): this; /** * Sets the projection’s 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): this; + fitSize(size: [number, number], object: ExtendedFeature): this; /** * Sets the projection’s 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>): this; + fitSize(size: [number, number], object: ExtendedFeatureCollection): this; /** * Sets the projection’s 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): 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): 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>): 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): 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): 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>): 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): 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 { +export interface GeoPath { /** * Renders the given object, which may be any GeoJSON feature or geometry object: * @@ -1222,7 +1234,7 @@ export interface GeoPath { * @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; +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): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature): this; /** * Sets the projection’s 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>): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection): this; /** * Sets the projection’s 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): this; + fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection): this; /** * Sets the projection’s 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): this; + fitSize(size: [number, number], object: ExtendedFeature): this; /** * Sets the projection’s 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>): this; + fitSize(size: [number, number], object: ExtendedFeatureCollection): this; /** * Sets the projection’s 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): this; + fitSize(size: [number, number], object: ExtendedGeometryCollection): this; /** * Returns true if x-reflection is enabled, which defaults to false. diff --git a/types/d3-geo/tsconfig.json b/types/d3-geo/tsconfig.json index f3661c3ad2..128bdf7ee8 100644 --- a/types/d3-geo/tsconfig.json +++ b/types/d3-geo/tsconfig.json @@ -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" ] -} \ No newline at end of file +}