Skip to content

Commit

Permalink
Update Typescript definition for @turf/line-segment
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed May 10, 2017
1 parent 56c85fb commit 862ae21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
23 changes: 21 additions & 2 deletions packages/turf-line-segment/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import {LineString, MultiLineString, Polygon, MultiPolygon, LineStrings} from '@turf/helpers'
/// <reference types="geojson" />

type LineString = GeoJSON.LineString;
type MultiLineString = GeoJSON.MultiLineString;
type Polygon = GeoJSON.Polygon;
type MultiPolygon = GeoJSON.MultiPolygon;
type GeometryObject = GeoJSON.GeometryObject;
type GeometryCollection = GeoJSON.GeometryCollection;
type Feature<Geom extends GeometryObject> = GeoJSON.Feature<Geom>;
type FeatureCollection<Geom extends GeometryObject> = GeoJSON.FeatureCollection<Geom>;
type Geoms = LineString | MultiLineString | Polygon | MultiPolygon;

// Not correctly supported in @types/geojson
interface FeatureGeometryCollection extends Feature<any> {
geometry: GeometryCollection
}

// Input & Output
type Input = Feature<Geoms> | FeatureCollection<Geoms> | Geoms | GeometryCollection | FeatureGeometryCollection;
type Output = FeatureCollection<LineString>;

/**
* http://turfjs.org/docs/#linesegment
*/
declare function lineSegment(geojson: LineString | MultiLineString | Polygon | MultiPolygon): LineStrings;
declare function lineSegment(geojson: Input): Output;
declare namespace lineSegment {}
export = lineSegment;
13 changes: 9 additions & 4 deletions packages/turf-line-segment/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {lineString, polygon, featureCollection, geometryCollection} from '@turf/helpers'
import * as lineSegment from '../'
import * as path from 'path'
const load = require('load-json-file')

const polygon: GeoJSON.Feature<GeoJSON.Polygon> = load.sync(path.join(__dirname, 'in', 'polygon.geojson'));
const poly = polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
const line = lineString([[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]);
const collection = featureCollection([poly, line]);
const geomCollection = geometryCollection([poly.geometry, line.geometry]);

// Test Types
lineSegment(polygon)
lineSegment(poly)
lineSegment(line)
lineSegment(collection)
lineSegment(geomCollection)

0 comments on commit 862ae21

Please sign in to comment.