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 orderByDistance with type generics #293

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

Conversation

leumasme
Copy link

@leumasme leumasme commented Dec 23, 2022

This change adds a generic type to the orderByDistance function.
It is not a breaking change, and just allows for easier usage of the function.
Specifically, the function was previously typed as returning GeolibInputCoordinates[] which is a type that includes all the different ways of representing coordinates, with no respect to which specific type the passed input coordinates actually have.
This was hard to use and not always complete as extra data could be added to the elements of the input coordinate array. This extra data would still be in the result of the function, but would not be in its return type.

Here is an example of what this change makes possible:

type CoordinatesAndExtraData = {
  lat: string, lon: string, locationName: string
};
// ... any data loaded here
let points: CoordinatesAndExtraData = generateSomeData();
let targetPoint: GeolibInputCoordinates = generateTargetPoint(); 
// Generate ordered list
let ordered = orderByDistance(targetPoint, points);
// This works but was previously disallowed by the types as locationName doesn't exist on `GeolibInputCoordinates`
console.log("The first point in the ordered list is "+ordered[0].locationName)

@bdow
Copy link

bdow commented Aug 16, 2023

This would be amazing to get merged! @manuelbieh - any reason to not merge this?

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.

2 participants