Skip to content

Commit

Permalink
Add additional typing hints (#53)
Browse files Browse the repository at this point in the history
* use labeled tuple elements for Point type

Using labeled tuple elements allows editors to show what values are expected in the different positions of the tuple.

* use mapped object type for Unit/Factors

Using a mapped object type allows the acceptable units names to be shared between the Factors type and the arguments to fromTile and the constructor.  This gives good editor support for the acceptable options to these methods.

* use labeled tuple elements for BBox type

Using labeled tuple elements allows editors to show what values are expected in the different positions of the tuple.
  • Loading branch information
tdillon authored Apr 12, 2022
1 parent f469d58 commit c34d08b
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions cheap-ruler.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
export type BBox = [number, number, number, number];
export type Point = [number, number];
export type BBox = [west: number, south: number, east: number, north: number];
export type Point = [longitude: number, latitude: number];
export type Line = Point[];
export type Points = Point[];
export type Polygon = Point[][];

export interface Factors {
kilometers: number;
miles: number;
nauticalmiles: number;
meters: number;
metres: number;
yards: number;
feet: number;
inches: number;
export type Unit =
'kilometers' |
'miles' |
'nauticalmiles' |
'meters' |
'metres' |
'yards' |
'feet' |
'inches'

export type Factors = {
[name in Unit]: number;
}

export default class CheapRuler {
public static fromTile(y: number, z: number, units?: string): CheapRuler;
public static fromTile(y: number, z: number, units?: Unit): CheapRuler;
public static units: Factors;

constructor(lat: number, units?: string);
constructor(lat: number, units?: Unit);

public distance(a: Point, b: Point): number;
public bearing(a: Point, b: Point): number;
Expand Down

0 comments on commit c34d08b

Please sign in to comment.