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

directions: Type error of via_waypoint field inside routeLeg #911

Open
kataiga opened this issue Dec 21, 2022 · 1 comment
Open

directions: Type error of via_waypoint field inside routeLeg #911

kataiga opened this issue Dec 21, 2022 · 1 comment
Assignees
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@kataiga
Copy link

kataiga commented Dec 21, 2022

Hello,

When I try to use the via_waypoint field of the 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:

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

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<void> => 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)
@kataiga kataiga added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 21, 2022
@wangela
Copy link
Member

wangela commented Dec 21, 2022

@kataiga Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants