turf
turf copied to clipboard
[Meta] Improve typescript support
Goals:
- #2158 Migrate turf-helpers/lib/geojson to
@types/geojson
- Drop turf-helpers/lib/geojson.ts altogether completely, or at least no more re-exporting types from
geojson
. - #2235 Should be able to use the top-level turf library directly in a Typescript project, rather than individual packages.
Related tickets:
-
#1658 compatibility with @types/geojson
-
#1906
-
#1289 export type declaration when published build (resolved?)
-
#1297 types play nice with mapbox-gl-js (this can be verified once a v7 alpha/beta release is published)
-
#1504 (perhaps this can be verified once a v7 alpha/beta release is published)
Hi. Any progress on this? The incompatibility between turf/geojson/mapboxgl is a continual sticking point for us.
I'd like to add that this library is type-incompatible with itself because of union return types. Here's an example of how to take a list of polygons and convert them to a collection of lines:
featureCollection(
places.flatMap(
({ geometry, name }) =>
(polygonToLine(geometry, { properties: { name } }) as FeatureCollection)
.features
)
)
It requires a type assertion.
Presumably, that's because certain arguments to polygonToLine
would cause switches between feature collections and feature output; otherwise this type should just get narrowed.
If it is because of a switch, it might make sense to make functions like this generic. A generic type could be used to restrict the allowable input options (specifically those output switches) and narrow the output type.
Generic typing would also need to be documented.
Any updates. I want to use Turf Mask but it does not support TypeScript.
Hi @alamenai Try the latest 7.0.0-alpha.114. Typescript support is be much improved in v7.