-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Hi @caseycesari, i love your library and all the work that has been done here !
But it is missing type definitions and the fact that @types/geojson isn't providing it is really confusing at the start of using the library.
I saw that someone did a typescript version on a fork of the library here but overall it's just a duplication of the current js with addition of bad types on top of it.
I added a custom type file on my side that types the lib with modern and precise typescript:
import {FeatureCollection, Feature, Geometry} from '@types/geojson'
export interface InvalidGeometryError extends Error {
item: any;
params: any;
}
export type Geoms = 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon' | 'GeoJSON'
export interface GeomsParams extends Partial<Record<Geoms, string>> {
Point?: string | string[]
}
export type Data = { [key: string]: any } | any[]
export interface Params extends GeomsParams {
doThrows?: {
invalidGeometry: boolean;
};
removeInvalidGeometries?: boolean;
extraGlobal?: { [key: string]: any };
extra?: { [key: string]: any };
crs?: any;
bbox?: any[];
include?: string[];
exclude?: string[];
isPostgres?: boolean;
GeoJSON?: string
}
export interface GEOJSON {
version: string;
defaults: Params;
errors: {
InvalidGeometryError: InvalidGeometryError;
};
isGeometryValid(geometry: Geometry): boolean;
parse<D extends Data = any, G extends Geometry | null = Geometry, P = GeoJsonProperties>(data: D, params?: Params, callback?: (geojson: D extends any [] ? FeatureCollection<G, P> : Feature<G, P>) => void): D extends any [] ? FeatureCollection<G, P> : Feature<G, P>;
}
const GeoJSON: GEOJSON;
export default GeoJSON;
export * from "@types/geojson"It uses @types/geojson and extend it to provide the types of your library.
It works perfectly, i have tested it with all the examples provided in the readme.
It won't change anything for the js part i would just add a geojson.d.ts file and declare it in the package.json.
I just need your feedback on the typescript if you have one and your approval for the pull request.