Skip to content

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

2 participants