googlemaps / googlemaps/google-maps-services-js

directions: Type error of via_waypoint field inside routeLeg

Open
#911 1 comment 0 reactions 1 assignee Claimed by @wangela View on GitHub
triage me type: bug
Dominant language
TypeScript
Stars
3.1k
Forks
654
Avg merge
3m
Merged PRs (30d)
4

Description

Hello,

When I try to use the [via_waypoint](https://developers.google.com/maps/documentation/directions/get-directions#DirectionsLeg-via_waypoint) field of the [DirectionsLeg](https://developers.google.com/maps/documentation/directions/get-directions#DirectionsLeg) (that is called `routeLeg` inside your code for some reason) I got this error `Property 'via_waypoint' does not exist on type 'RouteLeg'.ts(2339` but the data is present in the response and your documentation

an other thing that is wierd in the doc and may be related, it is said for the [Directions.legs](https://developers.google.com/maps/documentation/directions/get-directions#DirectionsRoute-legs):
>A separate leg will be present for each waypoint or destination specified.

But this is not the case actually if I send 0, 1, 13 waypoint i only got one leg what is the reel expected behavior ?

---

#### Environment details
NodeJS v16.14
npm package @googlemaps/google-maps-services-js v3.3.16

#### Steps to reproduce

1. call the directions api with a waypoint
2. try to use `directions.data.routes[i].legs[i].via_waypoint`
3. you will got typescript error

#### Code example

```javascript
import { Client } from '@googlemaps/google-maps-services-js';

const key = process.env.GOOGLE_API_KEY || '';
const client = new Client({});

export const getDistanceMatrix = (addresses: string[], departureTime?: Date): Promise => client
.directions({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: TS2322
params: {
key,
origin: addresses[0],
destination: addresses[addresses.length - 1],
waypoints: addresses.slice(1, -1).map((address) => `via:${address}`),
...departureTime
? {
traffic_model: 'best_guess',
departure_time: departureTime,
}
: {},
alternatives: true,
},
})
.then((directions) => {

console.log(directions.data.routes[0].legs[0].via_waypoint)
})

const adresses = [
"25 Rue de la Marbrerie, Lille, France",
"18 Rue Jules Guesde, 59650 Villeneuve-d'Ascq, France",
"Ecole Elémentaire Voltaire-Sévigné, Rue Emile Zola Lomme, Lille, France"
]

getDistanceMatrix(adresses)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.