mapbox/mapbox-sdk-js

"exclude must be a string." error using mbxDirections in mapbox-sdk-js 13.3

hanqiao69 opened this issue · 6 comments

Our team has been using mbxDirections to calculate road distance using Mapbox for ~2 months with the following configs.

await directionsService
      .getDirections({
        profile: 'driving',
        waypoints: stops.map((s) => ({
          coordinates: [s.longitude, s.latitude],
        })) as DirectionsWaypoint[],
        geometries: 'polyline',
        overview: 'full',
        steps: true,
        exclude: ['ferry'],
      })
      .send();

However, our API stopped working and started seeing Error: exclude must be a string. since 7/12/22.
I tried updating to the latest (13.4) of the sdk, and the same issue still remains.
I tried removing the sdk and instead querying the endpoint directly with the following CURL and it works

curl --location --request GET 'https://api.mapbox.com/directions/v5/mapbox/driving/-122.393806%2C37.786041%3B-122.401527%2C37.788712?geometries=polyline&overview=full&steps=true&exclude=ferry&access_token=<ACCESS_TOKEN_HERE>

I would like to confirm with mapbox that this is due to an API change that isn't being reflected in the sdk client. Thank you!

https://github.com/mapbox/mapbox-sdk-js/blob/main/docs/services.md#getdirections exclude must be a string so instead of exclude: ['ferry'] it should be exclude: 'ferry'

https://github.com/mapbox/mapbox-sdk-js/blob/main/docs/services.md#getdirections exclude must be a string so instead of exclude: ['ferry'] it should be exclude: 'ferry'

@andrewharvey I understand the change in the REST API. However, the mapbox-sdk still enforces exclude as Array instead of string (the old API). Thus, we are experiencing the aforementioned issue when trying to use the mapbox-sdk referenced here.

exclude: v.string,

from what I can see in the code exclude is asserted as string and then passed as the request query param.

This looks right, however, I just removed and re-added mapbox/mapbox-sdk via yarn and this is the library source code as I see it. Do you have any idea where this might come from? Maybe I'm using a different version of the sdk?

That's typescript, it's not something maintained here, there was some talk in #213

Thanks for the reference. So it seems like DefinitelyTyped is mis-translating certain type constraints, rendering the sdk in ts unusable.