From 846d821ff5ee2ecdc52cfbf0b32d193d3774c215 Mon Sep 17 00:00:00 2001 From: Ryan Blackman Date: Thu, 29 Aug 2019 20:05:09 -0500 Subject: [PATCH] Allow steps to be nested under google.maps.DirectionsLeg (#37963) --- types/googlemaps/googlemaps-tests.ts | 28 ++++++++++++++++++++++++++++ types/googlemaps/index.d.ts | 10 ++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/types/googlemaps/googlemaps-tests.ts b/types/googlemaps/googlemaps-tests.ts index a73fc00276..3c71e0af9d 100644 --- a/types/googlemaps/googlemaps-tests.ts +++ b/types/googlemaps/googlemaps-tests.ts @@ -793,3 +793,31 @@ const directionsWaypointLocationPlace: google.maps.DirectionsWaypoint = { const directionsWaypointStopover: google.maps.DirectionsWaypoint = { stopover: true, }; + +/***** google.maps.DirectionsService *****/ +let directionsService = new google.maps.DirectionsService(); + +directionsService.route({ + avoidFerries: true, + avoidHighways: true, + avoidTolls: true, + destination: 'destination', + origin: 'origin', + provideRouteAlternatives: true, + transitOptions: { + arrivalTime: new Date(), + departureTime: new Date(), + modes: [ + google.maps.TransitMode.BUS, + google.maps.TransitMode.RAIL + ], + routingPreference: google.maps.TransitRoutePreference.FEWER_TRANSFERS + }, + travelMode: google.maps.TravelMode.TRANSIT, + unitSystem: google.maps.UnitSystem.IMPERIAL +}, (result: google.maps.DirectionsResult, status: google.maps.DirectionsStatus) => { + const routes = result.routes; // $ExpectType DirectionsRoute[] + const legs = routes[0].legs; // $ExpectType DirectionsLeg[] + const steps = legs[0].steps; // $ExpectType DirectionsStep[] + steps[0].steps; // $ExpectType BaseDirectionsStep[] +}); diff --git a/types/googlemaps/index.d.ts b/types/googlemaps/index.d.ts index 31ca586d66..519400d908 100644 --- a/types/googlemaps/index.d.ts +++ b/types/googlemaps/index.d.ts @@ -1977,18 +1977,24 @@ declare namespace google.maps { via_waypoints: LatLng[]; } - interface DirectionsStep { + interface BaseDirectionsStep { distance: Distance; duration: Duration; end_location: LatLng; instructions: string; path: LatLng[]; start_location: LatLng; - steps: DirectionsStep; transit: TransitDetails; travel_mode: TravelMode; } + interface DirectionsStep extends BaseDirectionsStep { + /** + * This field will only be available if travel_mode is set to TRANSIT. + */ + steps: BaseDirectionsStep[]; + } + interface Distance { text: string; value: number;