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

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

Open
hanqiao69 opened this issue Jul 29, 2022 · 6 comments

Comments

@hanqiao69
Copy link

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!

@andrewharvey
Copy link
Collaborator

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'

@hanqiao69
Copy link
Author

hanqiao69 commented Jul 29, 2022

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.

@andrewharvey
Copy link
Collaborator

exclude: v.string,

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

@hanqiao69
Copy link
Author

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?

@andrewharvey
Copy link
Collaborator

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

@hanqiao69
Copy link
Author

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

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

No branches or pull requests

2 participants