Skip to content

fix(common): make DirectionsStep.steps an optional DirectionsStep[] - #1423

Draft
simonyang08 wants to merge 2 commits into
googlemaps:masterfrom
simonyang08:codex/gmsjs-1319-directionsstep-substeps
Draft

fix(common): make DirectionsStep.steps an optional DirectionsStep[]#1423
simonyang08 wants to merge 2 commits into
googlemaps:masterfrom
simonyang08:codex/gmsjs-1319-directionsstep-substeps

Conversation

@simonyang08

Copy link
Copy Markdown

Fixes #1319

The DirectionsStep interface in src/common.ts previously declared steps and transit_details as required non-optional fields, and declared steps as a single DirectionsStep rather than an array.

This does not match the Google Directions API response:

  • steps[i].steps is only populated for travel_mode === "transit" and is always returned as an array (see API docs: "If the directions include multiple modes of transportation, detailed directions will be provided for walking or driving steps in an inner steps array").
  • steps[i].transit_details is only returned for travel_mode === "transit".

This change:

  • Types steps as the optional DirectionsStep[].
  • Marks transit_details optional as well.

Both changes were requested in #1319 and the prior (now-closed) attempt at PR #1389.

Added regression test: src/common.directionsstep.test.ts (compile-time type assertions + runtime sanity checks), including a pinned TransitDetails-typed transit step. All 72 unit tests pass with the fix; the new test fails to compile against the previous typings.

Local checks:

  • npm run build (tsc): clean.
  • npx jest --runInBand ./src/: 72/72 pass.
  • bash test-module-loading.sh: cjs + esm loads succeed.

CLA: I will sign the Google Individual CLA when a maintainer approves.

Signed-off-by: simonyang08 ppt5928@gmail.com

The previous typings declared `steps: DirectionsStep` and
`transit_details: TransitDetails` on `DirectionsStep`, which did not
match the Google Directions API response:

* Substeps (`steps`) are returned as an array and only for transit
  travel mode; non-transit steps omit the field entirely.
* `transit_details` is only returned for transit travel mode.

Mark both fields optional and type `steps` as `DirectionsStep[]`.

Fixes googlemaps#1319

Signed-off-by: simonyang08 <ppt5928@gmail.com>
@google-cla

google-cla Bot commented Sep 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Signed-off-by: simonyang08 <ppt5928@gmail.com>
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

Successfully merging this pull request may close these issues.

Incorrect typings for DirectionsStep.step, (should be DirectionsStep[])

2 participants