-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating Common Types Package #1
Comments
…al and explicit. Added functionality in terms of generics to geometry and feature types. Reorganized types to a more conventional standard. Split out like types into their own files. Changes tracked in #1. AFFECTS PACKAGES: @esri/arcgis-rest-common-types BREAKING CHANGE: Converted interface ISpatialReference to type SpatialReference.|Shape of interface IFeature shape moved to ISpatialFeature.|Renamed interface IGeometry to IGeometryBase.|Removed type ElipticArc.|Renamed type JsonCurve to CurveAny.|Renamed IPolylineWithCurves to ICurvedPolyline.|Renamed IPolygonWithCurves to ICurvedPolygon.|Renamed type Position2D to Position.|Renamed the following string literal types: esriFieldType to EsriFieldType, esriGeometryType to EsriGeometryType,esriUnits to EsriUnits.
To-do:
|
Perhaps the Web Map Specification stuff needs to be separated somehow if it is conflicting with types defined elsewhere in the REST API. |
Wasn't aware of the Web Map Spec. That might make some more sense to split that out so that there is the rest-types and the webmap spec types. And good catch on the domain's. You are correct. And by the looks of it, it is really only on the Based on the discussion (Esri#515 (comment)), maybe these updates would be better suited for @types. If that's the case, would you be open to working on this with me? And if I'm not mistaken, we've actually met. I believe you gave some of us at DFW a demo of some of the work at WSDOT. Crazy stumbling into each other on here. |
I'd forgotten that I'd done this, but I made a very basic ArcGIS REST API type definition at @types. If I remember correctly I found it difficult to maintain due to the requirement that everything be defined in a single I'm not sure what the best way to handle these types is. |
Ahh gotcha. I've never contributed there so you have more experience than I do. Maybe I'll wait to see how some things shake out with the main repo. It looks like there is talks of creating a |
This issue is for keeping track of experimental updates to the common types package. Work is being done on the 'update-common-types' branch.
Overview
File organization
Certain types have been split out from
index.ts
into their own separate files for more a little more organization and easier maintenance.Suffix Convention
In order to be more explicit in what values are stored with coordinates, I have adapted a convention from other ESRI products that adds a suffix to the name of the geometry type. This allows for typescript to check that the
hasZ
andhasM
properties on an object are correctly set for an object. The following rules apply:IMultipoint
.IMultipointZ
.IMultipointM
.IMultipointZM
.MultipointAny
.This naming convention has been applied to Points, Positions, Multipoints, Curves, Polylines, Polygons, Geometries (generic type), & Feature Sets.
Typescript Generics
A lot of the types have had generics added to them to allow for developers to be a little more explicit if they so desire. When being more explicit, you can also gain the benefits of intellisense for correct property suggestions. Find out more information about the generics implementation in the 'New Features' section.
Breaking Updates to Existing References
Converted interface
ISpatialReference
to typeSpatialReference
.The type
SpatialReference
is now a union of theIWKIDSpatialReference
&IWKTSpatialReference
interfaces. See Spatial References in the 'New Features' section.Renamed interface
IGeometry
toIGeometryBase
.See Geometries in the 'New Features' section for more details on alternatives.
IGeometry
interface name implied a more comprehensive type than it actually was.Removed type
ElipticArc
.IArc
type. Was not referenced anywhere else.Renamed type
JsonCurve
toCurveAny
.See Curves in the 'New Features' section.
Renamed
IPolylineWithCurves
toICurvedPolyline
IPolylineZMWithCurves
.Renamed
IPolygonWithCurves
toICurvedPolygon
IPolygonZMWithCurves
.Renamed type
Position2D
toPosition
.See Positions in the 'New Features' section for more information.
Position
is now considered strictly 2-dimensional withPositionAny
taking the generic position type.Renamed the following string literal types:
esriFieldType
toEsriFieldType
esriGeometryType
toEsriGeometryType
esriUnits
toEsriUnits
Non-breaking Updates to Existing References
Changed the shape of
IField
.Changed type of
domain?
fromany
tostring
. RemovedexactMatch?
.domain
property should reference a domain name identified by a string. I didn't find any more documentation onexactMatch
to keep it at this level. It may be better suited on something that extendsIField
.IFeatureSet
no longer extendsIHasZM
as it is now strictly a 2-dimensional feature set.See Feature Sets in the 'New Features' section for more info.
IMultipoint
no longer extendsIHasZM
as it is now strictly a 2-dimensional multipoint.See Multipoints in the 'New Features' section for more info.
IPoint
no longer extendsIHasZM
as it is now strictly a 2-dimensional point.See Points in the 'New Features' section for more info.
IPolyline
no longer extendsIHasZM
as it is now strictly a 2-dimensional polyline.See Polylines in the 'New Features' section for more info.
IPolygon
no longer extendsIHasZM
as it is now strictly a 2-dimensional polygon.See Polygons in the 'New Features' section for more info.
Type
Position
is now strictly 2-dimensional.See Positions in the 'New Features' section for more info.
New features
Generics
As mentioned in the overview, a number of the interfaces have been updated to include generic type parameters, allowing developers to be more explicit if they so desire. This has the added benefit of stricter type checking, potentially reduced runtime errors, and more accurate intellisense tips. The generics have default values included in them so they are not always required but can be handy if they are used. For example, it can help guard instances like adding a polygon feature to a point feature set, or assigning an incompatible spatial reference. Consider the following example:
The following generic types were added where applicable:
Spatial References
In order to make the two shapes of a spatial reference interface explicit, the existing
ISpatialReference
was broken into the two different types discussed here, the WKID and WKT formats. These two new interfaces areIWKIDSpatialReference
andIWKTSpatialReference
. To make things a little easier, the union typeSpatialReference
was added as a replacement for the oldISpatialReference
interface.IWKIDSpatialReference
A spatial reference built off of a well-known ID.
IWKTSpatialReference
A spatial reference defined in the well-known text format.
SpatialReference
A convenient union type for when the shape of the spatial reference object isn't known.
Positions
These are the types that make up the points for multipoints, paths for polylines, and rings for polygons. These types typically won't be used outside of the geometry type definitions in the library, as they are pretty basic. They are, however, important to ensure that the geometry type has the correct position type.
Curves
Like positions, these are the types that can included in curvePaths for curved polylines, and curveRings for curved polygons. They are a union of the 4 different type of arcs (
IArc
,ICircularArc
,IBezierCurve
andIOldCircularArc
). Again, these types typically won't be used outside of the geometry type definitions in the library.Points
The
IPoint
interface has been limited to a simple 2-dimensional point location after following the naming convention discussed in the overview. Several additional interfaces have been added following the same naming convention to cover points with either Z or M values.Multipoints
Like the other geometry types, the
IMultipoint
interface has been limited to a simple 2-dimensional multipoint location after following the naming convention discussed in the overview. Several additional interfaces have been added following the same naming convention to cover multipoints with either Z or M values.Polylines
Like the other geometry types, the
IPolyline
interface has been limited to a simple 2-dimensional polyline location after following the naming convention discussed in the overview. Several additional interfaces have been added following the same naming convention to cover polylines with either Z or M values. TheIPolylineWithCurves
interface has been renamed to toICurvePolyline
for consistent use of the suffix rule.Polygons
Like the other geometry types, the
IPolygon
interface has been limited to a simple 2-dimensional polygon location after following the naming convention discussed in the overview. Several additional interfaces have been added following the same naming convention to cover polygons with either Z or M values. TheIPolygonWithCurves
interface has been renamed to toICurvePolygon
for consistent use of the suffix rule.Envelopes
In addition to the interface
IEnvelope
, the interfaceIEmptyEnvelope
was added. This is for envelopes that have no location in space. A union between these two types was also added asEnvelopeAny
.Geometries
The original
IGeometry
interface was just an object with a singlespatialReference
property. As an alternative, there is now a more generic union type namedGeometryAny
that encompasses each of the 5 different geometry types. These helper types also follow the dimensional suffix rule for additional typings.Feature Attributes
To allow for more explicit typings on a feature, the simple
IFeatureAttributes
was created. This doesn't do much on its own, but when specify it as a generic for feature sets you are able to check types against a features attribute property. For example:An additional benefit to the
IFeatureAttribute
generic is that it checks each field in the feature set's fields property for a corresponding field in the attributes interface.Feature Sets
In order to keep make sure that the correct values for dimensional properties (
hasZ
,hasM
) are assigned on a feature set, the suffix rule was followed for these as well. One exception to this rule is forIFeatureSetBase
, which is designed to be a set of features that do not have any geometry associated with them (e.g. tables).The text was updated successfully, but these errors were encountered: