turf icon indicating copy to clipboard operation
turf copied to clipboard

[Meta] Improve typescript support

Open twelch opened this issue 3 years ago • 2 comments

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)

twelch avatar Jul 25 '21 18:07 twelch

Hi. Any progress on this? The incompatibility between turf/geojson/mapboxgl is a continual sticking point for us.

robinsummerhill avatar Aug 04 '22 07:08 robinsummerhill

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.

david-morris avatar Aug 25 '22 08:08 david-morris

Any updates. I want to use Turf Mask but it does not support TypeScript.

alamenai avatar Mar 29 '24 22:03 alamenai

Hi @alamenai Try the latest 7.0.0-alpha.114. Typescript support is be much improved in v7.

smallsaucepan avatar Mar 29 '24 23:03 smallsaucepan