Replies: 2 comments
-
I‘d say we keep this discussion open for some time and gather other parts of the library that have a similar problem and then decide. Let’s first work without it! |
Beta Was this translation helpful? Give feedback.
-
The Turf interface is oriented towards the possibilities of JavaScript/Typescript. Since TurfDart is a direct port, we use what is available in Dart to stay as close as possible to the TurfJS interface (and documentation). I'm a fan of explicit approaches and like your suggestion. Also, we definitely have the potential to adapt the interface to the possibilities of Dart. But I agree with @lukas-h, now is not the right time. At the moment the priority is to port the complete functionality from TurfJS. It is also much easier to reprogram a feature in Dart if the implementation is as similar as possible to TurfJS. However, I was very happy to read about your suggestion. The idea of how to improve the library interface has also been on my mind for the last few days. |
Beta Was this translation helpful? Give feedback.
-
This discussion is in regards to finding a viable alternative to TypeScript's union types (as mentioned in #56) for use in generic function implementations like
nearestPointOnLine
, which is supposed to accept any ofLineString
,MultiLineString
,Feature<LineString>
, andFeature<MultiLineString>
.Proposal
I'm proposing using interfaces that unify certain geometry classes into groups by function - much like a trait in Rust. This admittedly adds some complexity to the library code, but it certainly improves usage, readability, and type safety for its consumers.
Example
Interface
Implementation
Example
Additional notes
This still doesn't allow the usage of
T | Feature<T>
, but that's unfortunately not possible due to Dart's constraints; we can't specialize interfaces based on generic types. However, this is something I believe we can live with, as the library consumer is only ever afeature.geometry
call away from converting it to a type that will fit.To start off, I would implement the following interfaces:
These are just off the top of my head, so Turf.js documentation needs to be scanned thoroughly to determine if any additional unifying interfaces are necessary and warranted, of course.
Beta Was this translation helpful? Give feedback.
All reactions