Skip to content
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

OLVectorLayer Type bug #15356

Closed
conbrad opened this issue Nov 20, 2023 · 4 comments
Closed

OLVectorLayer Type bug #15356

conbrad opened this issue Nov 20, 2023 · 4 comments
Labels

Comments

@conbrad
Copy link

conbrad commented Nov 20, 2023

Describe the bug
Typescript bug introduced in 8.2.0, using Typescript version 5.3.2

To Reproduce
Steps to reproduce the behavior:

  1. Create source from GeoJSON:
import VectorSource from 'ol/source/Vector'
import GeoJSON from 'ol/format/GeoJSON'

    const source = new VectorSource({
      features: new GeoJSON().readFeatures(geoJSON)
    })
  1. Create OLVectorLayer using source from step 1:
    const stationsLayer = new OLVectorLayer({
      source: source,
    })
  1. Get Typescript compilation error:
TS2322: Type 'VectorSource<FeatureLike>' is not assignable to type 'VectorSource<Feature<Geometry>>'.
  Type 'FeatureLike' is not assignable to type 'Feature<Geometry>'.
    Type 'RenderFeature' is missing the following properties from type 'Feature<Geometry>': on, once, un, geometryName_, and 39 more.

Expected behavior
A VectorSource from GeoJSON should be able to be supplied to OLVectorLayer without compilation errors.

@conbrad conbrad added the bug label Nov 20, 2023
@ahocevar
Copy link
Member

This should have been fixed with #15338 already. Please npm install ol@dev to verify.

@conbrad
Copy link
Author

conbrad commented Nov 21, 2023

This should have been fixed with #15338 already. Please npm install ol@dev to verify.

Verified, thanks!

@conbrad conbrad closed this as completed Nov 21, 2023
@vprint
Copy link

vprint commented Nov 28, 2023

Hello, i've made the following code :

/**
 * Request feature by id
 * @param id Id de l'entité
 * @returns Feature
 */
async function getFeatureById(id: string): Promise<FeatureLike | RenderFeature[] | undefined> {
  const result = await getJSON<FeatureCollection>(
    `${CONNECTION_PROPERTIES.FeatureServer.Collections}carto.td_features/items?id=${id}`,
    USER_MESSAGE.FEATURE_ERROR,
  );
  const feature = new GeoJSON().readFeature(result?.features[0], {
    dataProjection: 'EPSG:4326',
    featureProjection: 'EPSG:3857'
  });
  return feature;
}

This code returns FeatureLike | RenderFeature[] | undefined.

When i try to add theses FeatureLike | RenderFeature[] to a layer, i have a type error :

/**
* get and add feature to layer
*/
async function initializeFeature(): Promise<void> {
 // Récupération de l'entité non simplifiée et affichage sur le layer d'édition
 fullFeature = await ApiRequestor.getFeatureById(props.featureId as string)
 fullFeature ? editionLayerSource?.addFeature(fullFeature) : null
 editionLayer.setVisible(true)
}

"Argument of type 'FeatureLike | RenderFeature[]' is not assignable to parameter of type 'Feature'.
Type 'RenderFeature' is missing the following properties from type 'Feature': on, once, un, geometryName_, and 39 more.ts(2345)
let fullFeature: FeatureLike | RenderFeature[]"

Any idea ? (btw the code is still working)
version : ol 8.2.0 dev

@ahocevar
Copy link
Member

This will be fixed with #15379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants