fixed types for mapbox/wellknown (#41424)

* fixed types for mapbox/wellknown

* added author, added null return type and test

* added null to $ExpectType return type

* fixed tests
This commit is contained in:
Davide Scalzo
2020-01-16 20:16:44 +00:00
committed by Eli Barzilay
parent e760626f33
commit c5fd5466d6
3 changed files with 40 additions and 7 deletions

View File

@@ -1,7 +1,35 @@
// Type definitions for wellknown 0.5
// Project: https://github.com/mapbox/wellknown#readme
// Definitions by: Yair Tawil <https://github.com/yairtawil>
// Definitions by: Davide Scalzo <https://github.com/davodesign84>
// Yair Tawil <https://github.com/yairtawil>
// 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<T, C> {
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;

View File

@@ -1 +1,3 @@
{ "extends": "dtslint/dt.json" }
{
"extends": "dtslint/dt.json"
}

View File

@@ -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