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

More specific return types in Format#readFeatures #15338

Merged
merged 2 commits into from Nov 17, 2023

Conversation

ahocevar
Copy link
Member

@ahocevar ahocevar commented Nov 15, 2023

This pull request improves the types of the GeoJSON and MVT format so they can infer the return type of readFeatures() from the featureClass constructor option. This means that no type casts are needed any more in the code snippets below:

/** @type {Array<Feature>} */
const features = new GeoJSON().readFeatures(source);

/** @type {Array<RenderFeature>} */
const renderFeatures = new GeoJSON({featureClass: RenderFeature}).readFeatures(source);

For all other formats, the Feature return type is used for readFeatures(), as before v8.2.0.

Fixes #15334.

Copy link

📦 Preview the website for this branch here: https://deploy-preview-15338--ol-site.netlify.app/.

@ahocevar ahocevar changed the title Use generics to infer return type of GeoJSON#readFeatures More specific return types in Format#readFeatures Nov 16, 2023
Copy link
Member

@tschaub tschaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ahocevar ahocevar merged commit 7d543e8 into openlayers:main Nov 17, 2023
8 checks passed
@ahocevar ahocevar deleted the geojson-readfeatures-generics branch November 17, 2023 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OL8.2.0 GeoJSON readFeatures returns FeatureLike
2 participants