Skip to content

[Bug] Non-standard FeatureCollection type in editable-layers #202

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

Open
1 of 8 tasks
charlieforward9 opened this issue Feb 1, 2025 · 3 comments
Open
1 of 8 tasks
Labels
bug Something isn't working

Comments

@charlieforward9
Copy link

Module

  • deck.gl-community/arrow-layers
  • deck.gl-community/bing-maps
  • deck.gl-community/editable-layers
  • deck.gl-community/experimental
  • deck.gl-community/graph-layers
  • deck.gl-community/layers
  • deck.gl-community/react
  • deck.gl-community/react-graph-layer

Description

The FeatureCollection type in the editable-types does not conform to the standard GeoJSON.FeatureCollection type provided by the GeoJSON namespace.

Expected Behavior

It feels appropriate to use the GeoJSON namespace instead of redefinining the types

I am willing to contribute to this with some guidance and discussion on the correct approach.

Steps to Reproduce

 const [feature, setFeatures] = useState<GeoJSON.FeatureCollection>({
    type: "FeatureCollection",
    features: [],
  });
  const layer = new EditableGeoJsonLayer({
    id: "geojson-layer",
    data: feature, // ts error: see below 
    mode,
    selectedFeatureIndexes: [],

    onEdit: ({ updatedData }) => {
      setFeatures(updatedData);
    },
  });
Type 'FeatureCollection<Geometry, GeoJsonProperties>' is not assignable to type 'FeatureCollection'.
  Types of property 'features' are incompatible.
    Type 'Feature<Geometry, GeoJsonProperties>[]' is not assignable to type 'Feature[]'.
      Type 'Feature<Geometry, GeoJsonProperties>' is not assignable to type 'Feature'.
        Type 'Feature<Geometry, GeoJsonProperties>' is not assignable to type 'FeatureOf<MultiPolygon>'.
          Types of property 'geometry' are incompatible.
            Type 'Geometry' is not assignable to type 'MultiPolygon'.
              Type 'Polygon' is not assignable to type 'MultiPolygon'.
                Types of property 'type' are incompatible.
                  Type '"Polygon"' is not assignable to type '"MultiPolygon"'.

Environment

  • Framework version: 9.0.3
  • Browser: Chrome
  • OS: Mac

Logs

No response

@charlieforward9 charlieforward9 added the bug Something isn't working label Feb 1, 2025
@LeathanTeal
Copy link

LeathanTeal commented Feb 12, 2025

We are also experiencing issues with this type:

import { featureCollection } from "@turf/helpers";
import { EditableGeoJsonLayer } from "@deck.gl-community/editable-layers";

const displayFeatures = featureCollection([polygonFeature])

const layer = new EditableGeoJsonLayer({
        id: id,
        data: displayFeatures, // type error
        ...
    });
Type 'FeatureCollection<Geometry, GeoJsonProperties>' is not assignable to type 'FeatureCollection'.
  Types of property 'features' are incompatible.
    Type 'Feature<Geometry, GeoJsonProperties>[]' is not assignable to type 'Feature[]'.
      Type 'Feature<Geometry, GeoJsonProperties>' is not assignable to type 'Feature'.
        Type 'Feature<Geometry, GeoJsonProperties>' is not assignable to type 'FeatureOf<MultiPolygon>'.
          Types of property 'geometry' are incompatible.
            Type 'Geometry' is not assignable to type 'MultiPolygon'.
              Type 'Point' is not assignable to type 'MultiPolygon'.
                Types of property 'type' are incompatible.
                  Type '"Point"' is not assignable to type '"MultiPolygon"'.ts(2322)

layer-props.d.ts(74, 5): The expected type comes from property 'data' which is declared here on type 'Partial<LayerProps & { _subLayerProps?: { [subLayerId: string]: { [propName: string]: any; type?: ConstructorOf<Layer<{}>> | undefined; }; } | null | undefined; } & ... 4 more ... & Required<...>>'
(property) data?: DeckGLFeatureCollection | undefined

@timnyborg
Copy link

timnyborg commented Feb 27, 2025

Note that this package also relies on turf.js v6.5 packages, which define their own Feature, etc. types as well. Turf 7.0+ relies on the geojson types, so it'd be best to require the newer version at the same time as updating editable-layers' types, so everything is in sync.

@timnyborg
Copy link

I've put together a PR to sort this out (https://github.com/visgl/deck.gl-community/pull/221/files) as it's been a thorn in my side as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants