From 89667eb5cbee013f697ef1adef6582caa62385f3 Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Thu, 16 Nov 2017 14:50:49 -0800 Subject: [PATCH 1/6] Updated GeoJSON type definitions Updated to match RFC 7946 (https://tools.ietf.org/html/rfc7946). * Removed coordinate reference system types due to their removal from the standard. (https://tools.ietf.org/html/rfc7946#appendix-B.1) * Position arrays are now restricted to either two or three positions. (https://tools.ietf.org/html/rfc7946#section-3.1.1) * Feature and feature collection types are no longer generic. * Added support for foreign members. (https://tools.ietf.org/html/rfc7946#section-6.1) --- types/geojson/geojson-tests.ts | 93 ++++++++++-------- types/geojson/index.d.ts | 166 ++++++++++++++++++++------------- 2 files changed, 154 insertions(+), 105 deletions(-) diff --git a/types/geojson/geojson-tests.ts b/types/geojson/geojson-tests.ts index 4adb7f88f2..c9042c9da2 100644 --- a/types/geojson/geojson-tests.ts +++ b/types/geojson/geojson-tests.ts @@ -1,4 +1,9 @@ -let featureCollection: GeoJSON.FeatureCollection = { +import { + Feature, FeatureCollection, GeometryCollection, LineString, + MultiLineString, MultiPoint, MultiPolygon, Point, Polygon +} from "geojson"; + +let featureCollection: FeatureCollection = { type: "FeatureCollection", features: [ { @@ -34,7 +39,7 @@ let featureCollection: GeoJSON.FeatureCollection = { geometry: { type: "Polygon", coordinates: [ - [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] + [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] ] }, properties: { @@ -45,6 +50,9 @@ let featureCollection: GeoJSON.FeatureCollection = { } } ], + // Coordinate Systems no longer supported in GeoJSON as of RFC 7946. + // This will still work due to the standard's allowance for + // "foregin members", however. crs: { type: "link", properties: { @@ -54,7 +62,7 @@ let featureCollection: GeoJSON.FeatureCollection = { } }; -let featureWithPolygon: GeoJSON.Feature = { +const featureWithPolygon: Feature = { type: "Feature", bbox: [-180.0, -90.0, 180.0, 90.0], geometry: { @@ -66,57 +74,57 @@ let featureWithPolygon: GeoJSON.Feature = { properties: null }; -let point: GeoJSON.Point = { +const point: Point = { type: "Point", coordinates: [100.0, 0.0] }; // This type is commonly used in the turf package -let pointCoordinates: number[] = point.coordinates; +const pointCoordinates: number[] = point.coordinates; -let lineString: GeoJSON.LineString = { +const lineString: LineString = { type: "LineString", - coordinates: [ [100.0, 0.0], [101.0, 1.0] ] + coordinates: [[100.0, 0.0], [101.0, 1.0]] }; -let polygon: GeoJSON.Polygon = { +const polygon: Polygon = { type: "Polygon", coordinates: [ - [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] + [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]] ] }; -let polygonWithHole: GeoJSON.Polygon = { +const polygonWithHole: Polygon = { type: "Polygon", coordinates: [ - [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], - [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] + [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], + [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]] ] }; -let multiPoint: GeoJSON.MultiPoint = { +const multiPoint: MultiPoint = { type: "MultiPoint", - coordinates: [ [100.0, 0.0], [101.0, 1.0] ] + coordinates: [[100.0, 0.0], [101.0, 1.0]] }; -let multiLineString: GeoJSON.MultiLineString = { +const multiLineString: MultiLineString = { type: "MultiLineString", coordinates: [ - [ [100.0, 0.0], [101.0, 1.0] ], - [ [102.0, 2.0], [103.0, 3.0] ] + [[100.0, 0.0], [101.0, 1.0]], + [[102.0, 2.0], [103.0, 3.0]] ] }; -let multiPolygon: GeoJSON.MultiPolygon = { +const multiPolygon: MultiPolygon = { type: "MultiPolygon", coordinates: [ [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], - [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] + [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] ] }; -let geometryCollection: GeoJSON.GeometryCollection = { +const geometryCollection: GeometryCollection = { type: "GeometryCollection", geometries: [ { @@ -125,12 +133,12 @@ let geometryCollection: GeoJSON.GeometryCollection = { }, { type: "LineString", - coordinates: [ [101.0, 0.0], [102.0, 1.0] ] + coordinates: [[101.0, 0.0], [102.0, 1.0]] } ] }; -let feature: GeoJSON.Feature = { +let feature: Feature = { type: "Feature", geometry: lineString, properties: null @@ -172,31 +180,31 @@ featureCollection = { { type: "Feature", geometry: lineString, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: polygon, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: polygonWithHole, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: multiPoint, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: multiLineString, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: multiPolygon, - properties: {test: "OK"} + properties: { test: "OK" } }, { type: "Feature", geometry: geometryCollection, - properties: {test: "OK"} + properties: { test: "OK" } } ], crs: { @@ -209,7 +217,7 @@ featureCollection = { }; // Allow access to custom properties -const pt: GeoJSON.Feature = { +const pt: Feature = { type: "Feature", properties: { foo: "bar", @@ -221,9 +229,14 @@ const pt: GeoJSON.Feature = { coordinates: [0, 0] } }; -pt.properties.foo; -pt.properties.hello; -pt.properties[1]; + +if (pt.properties) { + if (pt.properties.foo == null || pt.properties.hello == null || pt.properties[1] == null) { + throw TypeError("Properties should not be null or undefined."); + } +} else { + throw TypeError("Feature should have a 'properties' property."); +} // Optional generic for properties @@ -232,19 +245,21 @@ interface TestProperty { hello: string; } -const typedPropertiesFeature: GeoJSON.Feature = { +const testProps: TestProperty = { + foo: "bar", + hello: "world" +}; + +const typedPropertiesFeature: Feature = { type: "Feature", - properties: { - foo: "bar", - hello: "world", - }, + properties: testProps, geometry: { type: "Point", coordinates: [0, 0] } }; -const typedPropertiesFeatureCollection: GeoJSON.FeatureCollection = { +const typedPropertiesFeatureCollection: FeatureCollection = { type: "FeatureCollection", features: [typedPropertiesFeature] }; diff --git a/types/geojson/index.d.ts b/types/geojson/index.d.ts index b916179fac..2b086bc382 100644 --- a/types/geojson/index.d.ts +++ b/types/geojson/index.d.ts @@ -1,123 +1,157 @@ -// Type definitions for GeoJSON Format Specification Revision 1.0 -// Project: http://geojson.org/ +// Type definitions for geojson 7946.0 +// Project: https://geojson.org/ // Definitions by: Jacob Bruun // Arne Schubert +// Jeff Jacobson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 +// Note: as of the RFC 7946 version of GeoJSON, Coordinate Reference Systems +// are no longer supported. (See https://tools.ietf.org/html/rfc7946#appendix-B)} + export as namespace GeoJSON; -/*** - * http://geojson.org/geojson-spec.html#geojson-objects +/** + * The valid values for the "type" property of GeoJSON geometry objects. + * https://tools.ietf.org/html/rfc7946#section-1.4 + */ +export type GeoJsonGeometryTypeNames = "Point" | "LineString" | "MultiPoint" | "Polygon" | "MultiLineString" | + "MultiPolygon" | "GeometryCollection"; + +/** + * The value values for the "type" property of GeoJSON Objects. + * https://tools.ietf.org/html/rfc7946#section-1.4 + */ +export type GeoJsonTypeNames = "FeatureCollection" | "Feature" | GeoJsonGeometryTypeNames; + +/** + * Bounding box + * https://tools.ietf.org/html/rfc7946#section-5 + */ +export type BoundingBox = [number, number, number, number] | [number, number, number, number, number]; + +/** + * A Position is an array of coordinates. + * https://tools.ietf.org/html/rfc7946#section-3.1.1 + */ +export type Position = [number, number] | [number, number, number]; + +/** + * The base GeoJSON object. + * https://tools.ietf.org/html/rfc7946#section-3 */ export interface GeoJsonObject { - type: string; - bbox?: number[]; - crs?: CoordinateReferenceSystem; + /** + * Allow foreign members as specified in https://tools.ietf.org/html/rfc7946#section-6.1 + */ + [key: string]: any; + /** + * Specifies the type of GeoJSON object. + */ + type: GeoJsonTypeNames; + /** + * Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections. + * https://tools.ietf.org/html/rfc7946#section-5 + */ + bbox?: BoundingBox; } -/*** - * http://geojson.org/geojson-spec.html#positions - */ -export type Position = number[]; - -/*** - * http://geojson.org/geojson-spec.html#geometry-objects - */ -export interface DirectGeometryObject extends GeoJsonObject { - coordinates: Position[][][] | Position[][] | Position[] | Position; -} /** - * GeometryObject supports geometry collection as well + * A geometry object. + * https://tools.ietf.org/html/rfc7946#section-3 */ -export type GeometryObject = DirectGeometryObject | GeometryCollection; +export interface GeometryObject extends GeoJsonObject { + type: GeoJsonGeometryTypeNames; +} -/*** - * http://geojson.org/geojson-spec.html#point +/** + * Point geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.2 */ -export interface Point extends DirectGeometryObject { +export interface Point extends GeometryObject { type: "Point"; coordinates: Position; } -/*** - * http://geojson.org/geojson-spec.html#multipoint +/** + * MultiPoint geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.3 */ -export interface MultiPoint extends DirectGeometryObject { +export interface MultiPoint extends GeometryObject { type: "MultiPoint"; coordinates: Position[]; } -/*** - * http://geojson.org/geojson-spec.html#linestring +/** + * LineString geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.4 */ -export interface LineString extends DirectGeometryObject { +export interface LineString extends GeometryObject { type: "LineString"; coordinates: Position[]; } -/*** - * http://geojson.org/geojson-spec.html#multilinestring +/** + * MultiLineString geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.5 */ -export interface MultiLineString extends DirectGeometryObject { +export interface MultiLineString extends GeometryObject { type: "MultiLineString"; coordinates: Position[][]; } -/*** - * http://geojson.org/geojson-spec.html#polygon +/** + * Polygon geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.6 */ -export interface Polygon extends DirectGeometryObject { +export interface Polygon extends GeometryObject { type: "Polygon"; coordinates: Position[][]; } -/*** - * http://geojson.org/geojson-spec.html#multipolygon +/** + * MultiPolygon geometry object. + * https://tools.ietf.org/html/rfc7946#section-3.1.7 */ -export interface MultiPolygon extends DirectGeometryObject { +export interface MultiPolygon extends GeometryObject { type: "MultiPolygon"; coordinates: Position[][][]; } -/*** - * http://geojson.org/geojson-spec.html#geometry-collection +/** + * Geometry Collection + * https://tools.ietf.org/html/rfc7946#section-3.1.8 */ -export interface GeometryCollection extends GeoJsonObject { +export interface GeometryCollection extends GeometryObject { type: "GeometryCollection"; geometries: GeometryObject[]; } -/*** +/** + * A feature object which contains a geometry and associated properties. * https://tools.ietf.org/html/rfc7946#section-3.2 */ -export interface Feature extends GeoJsonObject { +export interface Feature extends GeoJsonObject { type: "Feature"; - geometry: G; - properties: P; + /** + * The feature's geometry + */ + geometry: GeometryObject | null; + /** + * A value that uniquely identifies this feature in a + * https://tools.ietf.org/html/rfc7946#section-3.2. + */ id?: string | number; + /** + * Properties associated with this feature. + */ + properties: { [name: string]: any; } | null; } -/*** - * http://geojson.org/geojson-spec.html#feature-collection-objects +/** + * A collection of feature objects. + * https://tools.ietf.org/html/rfc7946#section-3.3 */ -export interface FeatureCollection extends GeoJsonObject { - type: "FeatureCollection"; - features: Array>; -} - -/*** - * http://geojson.org/geojson-spec.html#coordinate-reference-system-objects - */ -export interface CoordinateReferenceSystem { - type: string; - properties: any; -} - -export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem { - properties: { name: string }; -} - -export interface LinkedCoordinateReferenceSystem extends CoordinateReferenceSystem { - properties: { href: string; type: string }; +export interface FeatureCollection extends GeoJsonObject { + features: Feature[]; } From 335d12a4ee9af8e7f0c25dc6fe93a059e3ee9fa9 Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Thu, 16 Nov 2017 15:40:04 -0800 Subject: [PATCH 2/6] Modified typedefs dependent on "geojson" to accommodate changes. --- types/d3-geo/d3-geo-tests.ts | 4 ++-- types/d3-geo/index.d.ts | 4 +++- types/geojson2osm/geojson2osm-tests.ts | 2 +- types/geojson2osm/index.d.ts | 2 +- types/leaflet/index.d.ts | 28 +++++++++++++------------- types/leaflet/v0/index.d.ts | 12 +++++------ types/mapbox-gl/index.d.ts | 8 ++++---- types/polyline/index.d.ts | 2 +- types/shapefile/index.d.ts | 4 ++-- types/supercluster/index.d.ts | 2 +- types/tilebelt/index.d.ts | 4 ++-- 11 files changed, 37 insertions(+), 35 deletions(-) diff --git a/types/d3-geo/d3-geo-tests.ts b/types/d3-geo/d3-geo-tests.ts index 876461e3e9..e6014837a7 100644 --- a/types/d3-geo/d3-geo-tests.ts +++ b/types/d3-geo/d3-geo-tests.ts @@ -49,7 +49,7 @@ const sampleExtendedGeometryCollection: d3Geo.ExtendedGeometryCollection = { +const sampleFeature: GeoJSON.Feature = { type: 'Feature', geometry: samplePolygon, properties: { @@ -74,7 +74,7 @@ const sampleExtendedFeature2: d3Geo.ExtendedFeature = { +const sampleFeatureCollection: GeoJSON.FeatureCollection = { type: 'FeatureCollection', features: [ sampleFeature, diff --git a/types/d3-geo/index.d.ts b/types/d3-geo/index.d.ts index 4093b696e9..1d1d36fe91 100644 --- a/types/d3-geo/index.d.ts +++ b/types/d3-geo/index.d.ts @@ -36,7 +36,9 @@ export type GeoGeometryObjects = GeoJSON.GeometryObject | GeoSphere; export interface ExtendedGeometryCollection { type: string; bbox?: number[]; - crs?: GeoJSON.CoordinateReferenceSystem; + // GeoJSON removed the Coordinate System objects from the spec, but does allow + // "foreign members". + crs?: GeoJSON.GeoJsonObject; geometries: GeometryType[]; } diff --git a/types/geojson2osm/geojson2osm-tests.ts b/types/geojson2osm/geojson2osm-tests.ts index 887f10a83c..9d95de64c4 100644 --- a/types/geojson2osm/geojson2osm-tests.ts +++ b/types/geojson2osm/geojson2osm-tests.ts @@ -1,6 +1,6 @@ import { geojson2osm } from 'geojson2osm' -const features: GeoJSON.FeatureCollection = { +const features: GeoJSON.FeatureCollection = { type: 'FeatureCollection', features: [{ type: 'Feature', diff --git a/types/geojson2osm/index.d.ts b/types/geojson2osm/index.d.ts index 39b03de5bf..513348eeae 100644 --- a/types/geojson2osm/index.d.ts +++ b/types/geojson2osm/index.d.ts @@ -11,4 +11,4 @@ * @param features Input features * @returns OpenStreetMap XML */ -export function geojson2osm(features: GeoJSON.Feature | GeoJSON.FeatureCollection): any +export function geojson2osm(features: GeoJSON.Feature | GeoJSON.FeatureCollection): any diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index b1e7ead796..727478864a 100644 --- a/types/leaflet/index.d.ts +++ b/types/leaflet/index.d.ts @@ -583,7 +583,7 @@ export interface PolylineOptions extends PathOptions { export class Polyline extends Path { constructor(latlngs: LatLngExpression[], options?: PolylineOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; getLatLngs(): LatLng[]; setLatLngs(latlngs: LatLngExpression[]): this; isEmpty(): boolean; @@ -591,7 +591,7 @@ export class Polyline; + feature?: geojson.Feature; options: PolylineOptions; } @@ -616,14 +616,14 @@ export interface CircleMarkerOptions extends PathOptions { export class CircleMarker

extends Path { constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; setLatLng(latLng: LatLngExpression): this; getLatLng(): LatLng; setRadius(radius: number): this; getRadius(): number; options: CircleMarkerOptions; - feature?: geojson.Feature; + feature?: geojson.Feature; } export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker; @@ -671,7 +671,7 @@ export class LayerGroup

extends Layer { /** * Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection, GeoJSONFeatureCollection or Multipoint). */ - toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; /** * Adds the given layer to the group. @@ -725,7 +725,7 @@ export class LayerGroup

extends Layer { */ getLayerId(layer: Layer): number; - feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; } /** @@ -765,7 +765,7 @@ export class FeatureGroup

extends LayerGroup

{ */ export function featureGroup(layers?: Layer[]): FeatureGroup; -export type StyleFunction

= (feature?: geojson.Feature) => PathOptions; +export type StyleFunction

= (feature?: geojson.Feature) => PathOptions; export interface GeoJSONOptions

extends LayerOptions { /** @@ -781,7 +781,7 @@ export interface GeoJSONOptions

extends LayerOptions { * } * ``` */ - pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings + pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings /** * A Function defining the Path options for styling GeoJSON lines and polygons, @@ -807,7 +807,7 @@ export interface GeoJSONOptions

extends LayerOptions { * function (feature, layer) {} * ``` */ - onEachFeature?(feature: geojson.Feature, layer: Layer): void; + onEachFeature?(feature: geojson.Feature, layer: Layer): void; /** * A Function that will be used to decide whether to show a feature or not. @@ -820,7 +820,7 @@ export interface GeoJSONOptions

extends LayerOptions { * } * ``` */ - filter?(geoJsonFeature: geojson.Feature): boolean; + filter?(geoJsonFeature: geojson.Feature): boolean; /** * A Function that will be used for converting GeoJSON coordinates to LatLngs. @@ -838,7 +838,7 @@ export class GeoJSON

extends FeatureGroup

{ * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer * and/or coordsToLatLng functions if provided as options. */ - static geometryToLayer

(featureData: geojson.Feature, options?: GeoJSONOptions

): Layer; + static geometryToLayer(featureData: geojson.Feature, options?: GeoJSONOptions): Layer; /** * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or @@ -872,7 +872,7 @@ export class GeoJSON

extends FeatureGroup

{ /** * Normalize GeoJSON geometries/features into GeoJSON features. */ - static asFeature

(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; + static asFeature(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; constructor(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions

) /** @@ -1454,7 +1454,7 @@ export interface MarkerOptions extends InteractiveLayerOptions { export class Marker

extends Layer { constructor(latlng: LatLngExpression, options?: MarkerOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; getLatLng(): LatLng; setLatLng(latlng: LatLngExpression): this; setZIndexOffset(offset: number): this; @@ -1465,7 +1465,7 @@ export class Marker

extends Layer { // Properties options: MarkerOptions; dragging?: Handler; - feature?: geojson.Feature; + feature?: geojson.Feature; } export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; diff --git a/types/leaflet/v0/index.d.ts b/types/leaflet/v0/index.d.ts index efadd88e8f..d841a45133 100644 --- a/types/leaflet/v0/index.d.ts +++ b/types/leaflet/v0/index.d.ts @@ -223,7 +223,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the circle (GeoJSON Point Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -1716,7 +1716,7 @@ declare namespace L { * Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection). * Note: Descendent classes MultiPolygon & MultiPolyLine return `Feature`s, not `FeatureCollection`s */ - toGeoJSON(): GeoJSON.FeatureCollection|GeoJSON.Feature; + toGeoJSON(): GeoJSON.FeatureCollection|GeoJSON.Feature; //////////// //////////// @@ -2943,7 +2943,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the marker (GeoJSON Point Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; /** * Marker dragging handler (by both mouse and touch). @@ -3103,7 +3103,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the multipolygon (GeoJSON MultiPolygon Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -3144,7 +3144,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the multipolyline (GeoJSON MultiLineString Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -3565,7 +3565,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the polyline (GeoJSON LineString Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 6be9a465ef..6e61c90c70 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -54,9 +54,9 @@ declare namespace mapboxgl { unproject(point: PointLike): mapboxgl.LngLat; - queryRenderedFeatures(pointOrBox?: PointLike | PointLike[], parameters?: {layers?: string[], filter?: any[]}): GeoJSON.Feature[]; + queryRenderedFeatures(pointOrBox?: PointLike | PointLike[], parameters?: {layers?: string[], filter?: any[]}): GeoJSON.Feature[]; - querySourceFeatures(sourceID: string, parameters?: {sourceLayer?: string, filter?: any[]}): GeoJSON.Feature[]; + querySourceFeatures(sourceID: string, parameters?: {sourceLayer?: string, filter?: any[]}): GeoJSON.Feature[]; setStyle(style: mapboxgl.Style | string): this; @@ -507,11 +507,11 @@ declare namespace mapboxgl { constructor(options?: mapboxgl.GeoJSONSourceOptions); - setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; + setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; } export interface GeoJSONSourceOptions { - data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string; + data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string; maxzoom?: number; diff --git a/types/polyline/index.d.ts b/types/polyline/index.d.ts index 7a8b7eeb19..6961205212 100644 --- a/types/polyline/index.d.ts +++ b/types/polyline/index.d.ts @@ -9,7 +9,7 @@ interface Polyline { decode(string: string, precision?: number): number[][]; encode(coordinate: number[][], precision?: number): string; - fromGeoJSON(geojson: GeoJSON.LineString | GeoJSON.Feature, precision?: number): string; + fromGeoJSON(geojson: GeoJSON.LineString | GeoJSON.Feature, precision?: number): string; } declare var polyline: Polyline; diff --git a/types/shapefile/index.d.ts b/types/shapefile/index.d.ts index 54a18a2503..83852507e1 100644 --- a/types/shapefile/index.d.ts +++ b/types/shapefile/index.d.ts @@ -15,7 +15,7 @@ declare namespace shapefile { } interface Feature { done: boolean - value: GeoJSON.Feature + value: GeoJSON.Feature } interface Shapefile { bbox: Array @@ -23,7 +23,7 @@ declare namespace shapefile { } interface ShapefileStatic { open(shp: any, dbf?: any, options?: Options): Promise; - read(shp: any, dbf?: any, options?: Options): Promise>; + read(shp: any, dbf?: any, options?: Options): Promise; } } diff --git a/types/supercluster/index.d.ts b/types/supercluster/index.d.ts index 7fd487ae09..7463b4a43a 100644 --- a/types/supercluster/index.d.ts +++ b/types/supercluster/index.d.ts @@ -94,7 +94,7 @@ export class Supercluster { */ export default function supercluster(options: Options): Supercluster; -export type Point = GeoJSON.Feature; +export type Point = GeoJSON.Feature; export type Points = Point[]; export type Clusters = Cluster[]; export type TileFeatures = TileFeature[]; diff --git a/types/tilebelt/index.d.ts b/types/tilebelt/index.d.ts index f8d3adae1c..eed92f915b 100644 --- a/types/tilebelt/index.d.ts +++ b/types/tilebelt/index.d.ts @@ -14,12 +14,12 @@ declare namespace tilebelt { * * @name tileToGeoJSON * @param {Array} tile - * @returns {Feature} + * @returns {Feature} * @example * var poly = tileToGeoJSON([5, 10, 10]) * //=poly */ - tileToGeoJSON(tile: Array): GeoJSON.Feature + tileToGeoJSON(tile: Array): GeoJSON.Feature /** * Get the bbox of a tile From 3962926dc14798e685f9f2e49821ac1c33afc0d1 Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Mon, 20 Nov 2017 16:00:41 -0800 Subject: [PATCH 3/6] Revert "Modified typedefs dependent on "geojson" to accommodate changes." This reverts commit 335d12a4ee9af8e7f0c25dc6fe93a059e3ee9fa9. --- types/d3-geo/d3-geo-tests.ts | 4 ++-- types/d3-geo/index.d.ts | 4 +--- types/geojson2osm/geojson2osm-tests.ts | 2 +- types/geojson2osm/index.d.ts | 2 +- types/leaflet/index.d.ts | 28 +++++++++++++------------- types/leaflet/v0/index.d.ts | 12 +++++------ types/mapbox-gl/index.d.ts | 8 ++++---- types/polyline/index.d.ts | 2 +- types/shapefile/index.d.ts | 4 ++-- types/supercluster/index.d.ts | 2 +- types/tilebelt/index.d.ts | 4 ++-- 11 files changed, 35 insertions(+), 37 deletions(-) diff --git a/types/d3-geo/d3-geo-tests.ts b/types/d3-geo/d3-geo-tests.ts index e6014837a7..876461e3e9 100644 --- a/types/d3-geo/d3-geo-tests.ts +++ b/types/d3-geo/d3-geo-tests.ts @@ -49,7 +49,7 @@ const sampleExtendedGeometryCollection: d3Geo.ExtendedGeometryCollection = { type: 'Feature', geometry: samplePolygon, properties: { @@ -74,7 +74,7 @@ const sampleExtendedFeature2: d3Geo.ExtendedFeature = { type: 'FeatureCollection', features: [ sampleFeature, diff --git a/types/d3-geo/index.d.ts b/types/d3-geo/index.d.ts index 1d1d36fe91..4093b696e9 100644 --- a/types/d3-geo/index.d.ts +++ b/types/d3-geo/index.d.ts @@ -36,9 +36,7 @@ export type GeoGeometryObjects = GeoJSON.GeometryObject | GeoSphere; export interface ExtendedGeometryCollection { type: string; bbox?: number[]; - // GeoJSON removed the Coordinate System objects from the spec, but does allow - // "foreign members". - crs?: GeoJSON.GeoJsonObject; + crs?: GeoJSON.CoordinateReferenceSystem; geometries: GeometryType[]; } diff --git a/types/geojson2osm/geojson2osm-tests.ts b/types/geojson2osm/geojson2osm-tests.ts index 9d95de64c4..887f10a83c 100644 --- a/types/geojson2osm/geojson2osm-tests.ts +++ b/types/geojson2osm/geojson2osm-tests.ts @@ -1,6 +1,6 @@ import { geojson2osm } from 'geojson2osm' -const features: GeoJSON.FeatureCollection = { +const features: GeoJSON.FeatureCollection = { type: 'FeatureCollection', features: [{ type: 'Feature', diff --git a/types/geojson2osm/index.d.ts b/types/geojson2osm/index.d.ts index 513348eeae..39b03de5bf 100644 --- a/types/geojson2osm/index.d.ts +++ b/types/geojson2osm/index.d.ts @@ -11,4 +11,4 @@ * @param features Input features * @returns OpenStreetMap XML */ -export function geojson2osm(features: GeoJSON.Feature | GeoJSON.FeatureCollection): any +export function geojson2osm(features: GeoJSON.Feature | GeoJSON.FeatureCollection): any diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index 727478864a..b1e7ead796 100644 --- a/types/leaflet/index.d.ts +++ b/types/leaflet/index.d.ts @@ -583,7 +583,7 @@ export interface PolylineOptions extends PathOptions { export class Polyline extends Path { constructor(latlngs: LatLngExpression[], options?: PolylineOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; getLatLngs(): LatLng[]; setLatLngs(latlngs: LatLngExpression[]): this; isEmpty(): boolean; @@ -591,7 +591,7 @@ export class Polyline; options: PolylineOptions; } @@ -616,14 +616,14 @@ export interface CircleMarkerOptions extends PathOptions { export class CircleMarker

extends Path { constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; setLatLng(latLng: LatLngExpression): this; getLatLng(): LatLng; setRadius(radius: number): this; getRadius(): number; options: CircleMarkerOptions; - feature?: geojson.Feature; + feature?: geojson.Feature; } export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker; @@ -671,7 +671,7 @@ export class LayerGroup

extends Layer { /** * Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection, GeoJSONFeatureCollection or Multipoint). */ - toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; /** * Adds the given layer to the group. @@ -725,7 +725,7 @@ export class LayerGroup

extends Layer { */ getLayerId(layer: Layer): number; - feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; } /** @@ -765,7 +765,7 @@ export class FeatureGroup

extends LayerGroup

{ */ export function featureGroup(layers?: Layer[]): FeatureGroup; -export type StyleFunction

= (feature?: geojson.Feature) => PathOptions; +export type StyleFunction

= (feature?: geojson.Feature) => PathOptions; export interface GeoJSONOptions

extends LayerOptions { /** @@ -781,7 +781,7 @@ export interface GeoJSONOptions

extends LayerOptions { * } * ``` */ - pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings + pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings /** * A Function defining the Path options for styling GeoJSON lines and polygons, @@ -807,7 +807,7 @@ export interface GeoJSONOptions

extends LayerOptions { * function (feature, layer) {} * ``` */ - onEachFeature?(feature: geojson.Feature, layer: Layer): void; + onEachFeature?(feature: geojson.Feature, layer: Layer): void; /** * A Function that will be used to decide whether to show a feature or not. @@ -820,7 +820,7 @@ export interface GeoJSONOptions

extends LayerOptions { * } * ``` */ - filter?(geoJsonFeature: geojson.Feature): boolean; + filter?(geoJsonFeature: geojson.Feature): boolean; /** * A Function that will be used for converting GeoJSON coordinates to LatLngs. @@ -838,7 +838,7 @@ export class GeoJSON

extends FeatureGroup

{ * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer * and/or coordsToLatLng functions if provided as options. */ - static geometryToLayer(featureData: geojson.Feature, options?: GeoJSONOptions): Layer; + static geometryToLayer

(featureData: geojson.Feature, options?: GeoJSONOptions

): Layer; /** * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or @@ -872,7 +872,7 @@ export class GeoJSON

extends FeatureGroup

{ /** * Normalize GeoJSON geometries/features into GeoJSON features. */ - static asFeature(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; + static asFeature

(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; constructor(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions

) /** @@ -1454,7 +1454,7 @@ export interface MarkerOptions extends InteractiveLayerOptions { export class Marker

extends Layer { constructor(latlng: LatLngExpression, options?: MarkerOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; getLatLng(): LatLng; setLatLng(latlng: LatLngExpression): this; setZIndexOffset(offset: number): this; @@ -1465,7 +1465,7 @@ export class Marker

extends Layer { // Properties options: MarkerOptions; dragging?: Handler; - feature?: geojson.Feature; + feature?: geojson.Feature; } export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; diff --git a/types/leaflet/v0/index.d.ts b/types/leaflet/v0/index.d.ts index d841a45133..efadd88e8f 100644 --- a/types/leaflet/v0/index.d.ts +++ b/types/leaflet/v0/index.d.ts @@ -223,7 +223,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the circle (GeoJSON Point Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -1716,7 +1716,7 @@ declare namespace L { * Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection). * Note: Descendent classes MultiPolygon & MultiPolyLine return `Feature`s, not `FeatureCollection`s */ - toGeoJSON(): GeoJSON.FeatureCollection|GeoJSON.Feature; + toGeoJSON(): GeoJSON.FeatureCollection|GeoJSON.Feature; //////////// //////////// @@ -2943,7 +2943,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the marker (GeoJSON Point Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; /** * Marker dragging handler (by both mouse and touch). @@ -3103,7 +3103,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the multipolygon (GeoJSON MultiPolygon Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -3144,7 +3144,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the multipolyline (GeoJSON MultiLineString Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } @@ -3565,7 +3565,7 @@ declare namespace L { /** * Returns a GeoJSON representation of the polyline (GeoJSON LineString Feature). */ - toGeoJSON(): GeoJSON.Feature; + toGeoJSON(): GeoJSON.Feature; } } diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 6e61c90c70..6be9a465ef 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -54,9 +54,9 @@ declare namespace mapboxgl { unproject(point: PointLike): mapboxgl.LngLat; - queryRenderedFeatures(pointOrBox?: PointLike | PointLike[], parameters?: {layers?: string[], filter?: any[]}): GeoJSON.Feature[]; + queryRenderedFeatures(pointOrBox?: PointLike | PointLike[], parameters?: {layers?: string[], filter?: any[]}): GeoJSON.Feature[]; - querySourceFeatures(sourceID: string, parameters?: {sourceLayer?: string, filter?: any[]}): GeoJSON.Feature[]; + querySourceFeatures(sourceID: string, parameters?: {sourceLayer?: string, filter?: any[]}): GeoJSON.Feature[]; setStyle(style: mapboxgl.Style | string): this; @@ -507,11 +507,11 @@ declare namespace mapboxgl { constructor(options?: mapboxgl.GeoJSONSourceOptions); - setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; + setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; } export interface GeoJSONSourceOptions { - data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string; + data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string; maxzoom?: number; diff --git a/types/polyline/index.d.ts b/types/polyline/index.d.ts index 6961205212..7a8b7eeb19 100644 --- a/types/polyline/index.d.ts +++ b/types/polyline/index.d.ts @@ -9,7 +9,7 @@ interface Polyline { decode(string: string, precision?: number): number[][]; encode(coordinate: number[][], precision?: number): string; - fromGeoJSON(geojson: GeoJSON.LineString | GeoJSON.Feature, precision?: number): string; + fromGeoJSON(geojson: GeoJSON.LineString | GeoJSON.Feature, precision?: number): string; } declare var polyline: Polyline; diff --git a/types/shapefile/index.d.ts b/types/shapefile/index.d.ts index 83852507e1..54a18a2503 100644 --- a/types/shapefile/index.d.ts +++ b/types/shapefile/index.d.ts @@ -15,7 +15,7 @@ declare namespace shapefile { } interface Feature { done: boolean - value: GeoJSON.Feature + value: GeoJSON.Feature } interface Shapefile { bbox: Array @@ -23,7 +23,7 @@ declare namespace shapefile { } interface ShapefileStatic { open(shp: any, dbf?: any, options?: Options): Promise; - read(shp: any, dbf?: any, options?: Options): Promise; + read(shp: any, dbf?: any, options?: Options): Promise>; } } diff --git a/types/supercluster/index.d.ts b/types/supercluster/index.d.ts index 7463b4a43a..7fd487ae09 100644 --- a/types/supercluster/index.d.ts +++ b/types/supercluster/index.d.ts @@ -94,7 +94,7 @@ export class Supercluster { */ export default function supercluster(options: Options): Supercluster; -export type Point = GeoJSON.Feature; +export type Point = GeoJSON.Feature; export type Points = Point[]; export type Clusters = Cluster[]; export type TileFeatures = TileFeature[]; diff --git a/types/tilebelt/index.d.ts b/types/tilebelt/index.d.ts index eed92f915b..f8d3adae1c 100644 --- a/types/tilebelt/index.d.ts +++ b/types/tilebelt/index.d.ts @@ -14,12 +14,12 @@ declare namespace tilebelt { * * @name tileToGeoJSON * @param {Array} tile - * @returns {Feature} + * @returns {Feature} * @example * var poly = tileToGeoJSON([5, 10, 10]) * //=poly */ - tileToGeoJSON(tile: Array): GeoJSON.Feature + tileToGeoJSON(tile: Array): GeoJSON.Feature /** * Get the bbox of a tile From f12705b83b35eb0c9c96aaf6211113431738022a Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Mon, 20 Nov 2017 16:23:57 -0800 Subject: [PATCH 4/6] Made revisions suggested by other devs. * Corrected number of elements for 3D bounding boxes. (Mistakenly had five elements instead of six.) * Renamed "BoundingBox" to "BBox" to shorten name. * Restored generic types to Feature and FeatureCollection. * Removed the support for foreign members on GeoJsonObject. Users can instead extend the interface or use "&". --- types/geojson/geojson-tests.ts | 37 +++++++++------------------- types/geojson/index.d.ts | 44 ++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/types/geojson/geojson-tests.ts b/types/geojson/geojson-tests.ts index c9042c9da2..ce8c62418e 100644 --- a/types/geojson/geojson-tests.ts +++ b/types/geojson/geojson-tests.ts @@ -1,9 +1,10 @@ import { + BBox, Feature, FeatureCollection, GeometryCollection, LineString, - MultiLineString, MultiPoint, MultiPolygon, Point, Polygon + MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, GeometryObject } from "geojson"; -let featureCollection: FeatureCollection = { +let featureCollection: FeatureCollection = { type: "FeatureCollection", features: [ { @@ -49,20 +50,10 @@ let featureCollection: FeatureCollection = { } } } - ], - // Coordinate Systems no longer supported in GeoJSON as of RFC 7946. - // This will still work due to the standard's allowance for - // "foregin members", however. - crs: { - type: "link", - properties: { - href: "http://example.com/crs/42", - type: "proj4" - } - } + ] }; -const featureWithPolygon: Feature = { +const featureWithPolygon: Feature = { type: "Feature", bbox: [-180.0, -90.0, 180.0, 90.0], geometry: { @@ -138,11 +129,12 @@ const geometryCollection: GeometryCollection = { ] }; -let feature: Feature = { +let feature: Feature = { type: "Feature", geometry: lineString, properties: null }; + feature = { type: "Feature", geometry: polygon, @@ -206,18 +198,11 @@ featureCollection = { geometry: geometryCollection, properties: { test: "OK" } } - ], - crs: { - type: "link", - properties: { - href: "http://example.com/crs/42", - type: "proj4" - } - } + ] }; // Allow access to custom properties -const pt: Feature = { +const pt: Feature = { type: "Feature", properties: { foo: "bar", @@ -250,7 +235,7 @@ const testProps: TestProperty = { hello: "world" }; -const typedPropertiesFeature: Feature = { +const typedPropertiesFeature: Feature = { type: "Feature", properties: testProps, geometry: { @@ -259,7 +244,7 @@ const typedPropertiesFeature: Feature = { } }; -const typedPropertiesFeatureCollection: FeatureCollection = { +const typedPropertiesFeatureCollection: FeatureCollection = { type: "FeatureCollection", features: [typedPropertiesFeature] }; diff --git a/types/geojson/index.d.ts b/types/geojson/index.d.ts index 2b086bc382..936756ff86 100644 --- a/types/geojson/index.d.ts +++ b/types/geojson/index.d.ts @@ -15,45 +15,51 @@ export as namespace GeoJSON; * The valid values for the "type" property of GeoJSON geometry objects. * https://tools.ietf.org/html/rfc7946#section-1.4 */ -export type GeoJsonGeometryTypeNames = "Point" | "LineString" | "MultiPoint" | "Polygon" | "MultiLineString" | +export type GeoJsonGeometryTypes = "Point" | "LineString" | "MultiPoint" | "Polygon" | "MultiLineString" | "MultiPolygon" | "GeometryCollection"; /** * The value values for the "type" property of GeoJSON Objects. * https://tools.ietf.org/html/rfc7946#section-1.4 */ -export type GeoJsonTypeNames = "FeatureCollection" | "Feature" | GeoJsonGeometryTypeNames; +export type GeoJsonTypes = "FeatureCollection" | "Feature" | GeoJsonGeometryTypes; /** * Bounding box * https://tools.ietf.org/html/rfc7946#section-5 */ -export type BoundingBox = [number, number, number, number] | [number, number, number, number, number]; +export type BBox = [number, number, number, number] | [number, number, number, number, number, number]; /** * A Position is an array of coordinates. * https://tools.ietf.org/html/rfc7946#section-3.1.1 + * Array should contain between two and three elements. + * The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values), + * but the current specification only allows X, Y, and (optionally) Z to be defined. */ -export type Position = [number, number] | [number, number, number]; +export type Position = number[]; // [number, number] | [number, number, number]; /** * The base GeoJSON object. - * https://tools.ietf.org/html/rfc7946#section-3 + * https://tools.ietf.org/html/rfc7946#section-3 + * The GeoJSON specification also allows foreign members + * (https://tools.ietf.org/html/rfc7946#section-6.1) + * Developers should use "&" type in TypeScript or extend the interface + * to add these foreign members. */ export interface GeoJsonObject { - /** - * Allow foreign members as specified in https://tools.ietf.org/html/rfc7946#section-6.1 - */ - [key: string]: any; + // Don't include foreign members directly into this type def. + // in order to preserve type safety. + // [key: string]: any; /** * Specifies the type of GeoJSON object. */ - type: GeoJsonTypeNames; + type: GeoJsonTypes; /** * Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections. * https://tools.ietf.org/html/rfc7946#section-5 */ - bbox?: BoundingBox; + bbox?: BBox; } /** @@ -61,7 +67,7 @@ export interface GeoJsonObject { * https://tools.ietf.org/html/rfc7946#section-3 */ export interface GeometryObject extends GeoJsonObject { - type: GeoJsonGeometryTypeNames; + type: GeoJsonGeometryTypes; } /** @@ -124,19 +130,21 @@ export interface MultiPolygon extends GeometryObject { */ export interface GeometryCollection extends GeometryObject { type: "GeometryCollection"; - geometries: GeometryObject[]; + geometries: Array; } +export type GeoJsonProperties = { [name: string]: any; } | null; + /** * A feature object which contains a geometry and associated properties. * https://tools.ietf.org/html/rfc7946#section-3.2 */ -export interface Feature extends GeoJsonObject { +export interface Feature extends GeoJsonObject { type: "Feature"; /** * The feature's geometry */ - geometry: GeometryObject | null; + geometry: G | null; /** * A value that uniquely identifies this feature in a * https://tools.ietf.org/html/rfc7946#section-3.2. @@ -145,13 +153,13 @@ export interface Feature extends GeoJsonObject { /** * Properties associated with this feature. */ - properties: { [name: string]: any; } | null; + properties: P | null; } /** * A collection of feature objects. * https://tools.ietf.org/html/rfc7946#section-3.3 */ -export interface FeatureCollection extends GeoJsonObject { - features: Feature[]; +export interface FeatureCollection extends GeoJsonObject { + features: Array>; } From 5c544da4bd563e1264a722e7e8dc4ad7ce6c271b Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Tue, 21 Nov 2017 10:26:40 -0800 Subject: [PATCH 5/6] Added missing space --- types/geojson/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/geojson/index.d.ts b/types/geojson/index.d.ts index 936756ff86..d6ba411e3f 100644 --- a/types/geojson/index.d.ts +++ b/types/geojson/index.d.ts @@ -130,7 +130,7 @@ export interface MultiPolygon extends GeometryObject { */ export interface GeometryCollection extends GeometryObject { type: "GeometryCollection"; - geometries: Array; + geometries: Array; } export type GeoJsonProperties = { [name: string]: any; } | null; From 39d7d3ab396f96c80208e3144fff530135c6e268 Mon Sep 17 00:00:00 2001 From: Jeff Jacobson Date: Tue, 21 Nov 2017 15:38:42 -0800 Subject: [PATCH 6/6] fixed type def --- types/geojson/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/geojson/index.d.ts b/types/geojson/index.d.ts index d6ba411e3f..e6783255eb 100644 --- a/types/geojson/index.d.ts +++ b/types/geojson/index.d.ts @@ -130,7 +130,7 @@ export interface MultiPolygon extends GeometryObject { */ export interface GeometryCollection extends GeometryObject { type: "GeometryCollection"; - geometries: Array; + geometries: Array; } export type GeoJsonProperties = { [name: string]: any; } | null;