diff --git a/types/wellknown/index.d.ts b/types/wellknown/index.d.ts index 0b100e5c33..9aa92e0462 100644 --- a/types/wellknown/index.d.ts +++ b/types/wellknown/index.d.ts @@ -1,7 +1,35 @@ // Type definitions for wellknown 0.5 // Project: https://github.com/mapbox/wellknown#readme -// Definitions by: Yair Tawil +// Definitions by: Davide Scalzo +// Yair Tawil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export function parse(input: string): {}; -export function stringify(gj: {}): string; +export type GeoJSONPosition = [number, number] | [number, number, number]; + +export interface Geometry { + type: T; + coordinates: C; +} + +export type GeoJSONPoint = Geometry<"Point", GeoJSONPosition>; +export type GeoJSONMultiPoint = Geometry<"MultiPoint", GeoJSONPosition[]>; + +export type GeoJSONLineString = Geometry<"LineString", GeoJSONPosition[]>; + +export type GeoJSONMultiLineString = Geometry<"MultiLineString", GeoJSONPosition[][]>; + +export type GeoJSONPolygon = Geometry<"Polygon", GeoJSONPosition[][]>; + +export type GeoJSONMultiPolygon = Geometry<"MultiPolygon", GeoJSONPosition[][][]>; + +export type GeoJSONGeometry = + | GeoJSONPoint + | GeoJSONMultiPoint + | GeoJSONLineString + | GeoJSONMultiLineString + | GeoJSONPolygon + | GeoJSONMultiPolygon + | null; + +export function parse(input: string): GeoJSONGeometry; +export function stringify(gj: GeoJSONGeometry): string; diff --git a/types/wellknown/tslint.json b/types/wellknown/tslint.json index 3db14f85ea..e60c15844f 100644 --- a/types/wellknown/tslint.json +++ b/types/wellknown/tslint.json @@ -1 +1,3 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/wellknown/wellknown-tests.ts b/types/wellknown/wellknown-tests.ts index 0f1bcd656e..1dc821f1b8 100644 --- a/types/wellknown/wellknown-tests.ts +++ b/types/wellknown/wellknown-tests.ts @@ -1,7 +1,10 @@ import * as wellknown from 'wellknown'; -wellknown.parse("POINT(1 2)"); -const geoJson: {} = { + +wellknown.parse("POINT(1 2)"); // $ExpectType GeoJSONGeometry + +const geoJson: wellknown.GeoJSONGeometry = { coordinates: [1, 2], type: "Point" }; -wellknown.stringify(geoJson); + +wellknown.stringify(geoJson); // $ExpectType string