Skip to content

stricter type definitions for the geojson output #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
},
"devDependencies": {
"@mapbox/geojson-rewind": "^0.5.2",
"@types/geojson": "^7946.0.16",
"@types/node": "^22.10.2",
"@types/which-polygon": "^2.2.5",
"c8": "^10.1.3",
"esbuild": "^0.24.0",
"npm-run-all": "^4.1.5",
Expand Down
13 changes: 7 additions & 6 deletions src/country-coder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Feature, FeatureCollection, Geometry, Position } from 'geojson';
import whichPolygon from 'which-polygon';
import rawBorders from './data/borders.json';

Expand Down Expand Up @@ -72,24 +73,24 @@ type RegionFeatureProperties = {
// The side of the road that traffic drives on within this feature
// - `right`
// - `left`
driveSide: string | undefined;
driveSide: 'left' | 'right' | undefined;

// The unit used for road traffic speeds within this feature
// - `mph`: miles per hour
// - `km/h`: kilometers per hour
roadSpeedUnit: string | undefined;
roadSpeedUnit: 'mph' | 'km/h' | undefined;

// The unit used for road vehicle height restrictions within this feature
// - `ft`: feet and inches
// - `m`: meters
roadHeightUnit: string | undefined;
roadHeightUnit: 'ft' | 'm' | undefined;

// The international calling codes for this feature, sometimes including area codes
// e.g. `1`, `1 340`
callingCodes: Array<string> | undefined;
};
type RegionFeature = { type: string; geometry: any; properties: RegionFeatureProperties };
type RegionFeatureCollection = { type: string; features: Array<RegionFeature> };
type RegionFeature = Feature<Geometry, RegionFeatureProperties>;
type RegionFeatureCollection = FeatureCollection<Geometry, RegionFeatureProperties>;
type Vec2 = [number, number]; // [lon, lat]
type Bbox = [number, number, number, number]; // [minLon, minLat, maxLon, maxLat]
type PointGeometry = { type: string; coordinates: Vec2 };
Expand Down Expand Up @@ -698,7 +699,7 @@ export function aggregateFeature(id: string | number): RegionFeature | null {
const features = featuresIn(id, false);
if (features.length === 0) return null;

let aggregateCoordinates = [];
let aggregateCoordinates: Position[][][] = [];
for (const feature of features) {
if (feature.geometry?.type === 'MultiPolygon' && feature.geometry.coordinates) {
aggregateCoordinates = aggregateCoordinates.concat(feature.geometry.coordinates);
Expand Down