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

Improve NearestPoint type for @turf/nearest-point so that it keeps the properties of the points in the FeatureCollection #2861

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EmilJunker
Copy link

Please provide the following when creating a PR:

This PR improves the NearestPoint type and the type definition for the nearestPoint function.

Consider the following example in TypeScript:

const coordinatesList = [[0, 0], [1, 1], [0, 1]];
const pointsList = coordinatesList.map((coordinate, i) => {
    return turf.point(coordinate, {
        name: `point${i}`
    });
});
const pointsCollection = turf.featureCollection(pointsList);
const myNearestPoint = turf.nearestPoint(turf.point([2, 2]), pointsCollection);

With the old behaviour myNearestPoint.properties.name is of type any according to TypeScript.

With the changes in this PR, the type of myNearestPoint.properties.name is correctly inferred as string.

This change should be non-breaking.

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.

1 participant