Replies: 3 comments 13 replies
-
Multiple object shapes are not currently supported. Is my understanding correct? That we're talking about objects with multiple shapes? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I think what we're talking about here is the type t = ...t1 | A(int) and the usual syntax So |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying to model GeoJSON using rescript@11 types, just to see if I can, and am stumbling on just a few issues that I think should be feasible (though not easy) to fix since all the necessary features do exist in various forms. So I figured I'd document this as a prominent use case.
See the full TypeScript type definitions for reference.
The big problem is that a GeoJSON document can be either a single geometry object (of which there are several kinds), a "feature" which contains geometry, or a feature collection. These all use a
type
tag, but because geometry objects are included in several different types, modeling this requires structural typing. And unfortunately@tag
only works on nominal variants, not structural (polymorphic) ones. This is also the case with inline records, which is necessary for@tag
to be useful, so that's another hurdle.Essentially, I'd like to define the types like this:
Another minor problem is that positions and bounding boxes are arrays of different arities. These could be modeled with an unboxed tagged variant containing tuples of different arities, and possibly a constructor an array to cover the remaining arities. E.g.:
Lots of edge cases to consider though. A further improvement could be to (optionally) model inline records in unboxed variants as arrays, so that it could be:
Beta Was this translation helpful? Give feedback.
All reactions