perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

Wrong type definition in route method callback #562

Closed samirbraga closed 4 years ago

samirbraga commented 4 years ago

Hi, I have noted that the method route of class OSRMv1 has a parameter called callback typed as (args?: any) => void, but the callback expects an error as the first argument and routes as second. The code follows:

class OSRMv1 implements IRouter {
    constructor(options?: OSRMOptions);

    route(waypoints: Waypoint[], callback: (args?: any) => void, context?: {}, options?: RoutingOptions): void ;
    buildRouteUrl(waypoints: Waypoint[], options: RoutingOptions): string;
}

The typescript compiler raise an exception and the only way I made it work was:


router.route(waypoints, function () {
    const routes = [arguments[1]];
    ...
perliedman commented 4 years ago

Hi! Thanks for giving a heads up. Unfortunately, I am not responsible for the TypeScript definitions for this library, and they are not a part of the library itself. Since I don't personally use TypeScript, I am not even sure how it works our how the definitions are maintained, but I hope you can figure it out!