googlemaps / googlemaps/google-maps-services-js

Refine typings for `AutocompleteRequest.types` to allow for all variations allowed by the API

Open
#974 1 comment 1 reaction 1 assignee Claimed by @wangela View on GitHub
next major: breaking change type: bug
Dominant language
TypeScript
Stars
3.1k
Forks
654
Avg merge
3m
Merged PRs (30d)
4

Description

### Issue description

[In the documentation for the `placeAutocomplete` method](https://developers.google.com/maps/documentation/places/web-service/autocomplete#place_types) it is said that it supports

> Up to five values from [Table 1](https://developers.google.com/maps/documentation/places/web-service/supported_types#table1) or [Table 2](https://developers.google.com/maps/documentation/places/web-service/supported_types#table2)

separated by a vertical bar `|` as a valid value for the `types` parameter of the `autocomplete` endpoint.

However, in [`places/autocomplete.ts`](https://github.com/googlemaps/google-maps-services-js/blob/master/src/places/autocomplete.ts) the type of the `types` property is an enum [`PlaceAutocompleteType`](https://github.com/googlemaps/google-maps-services-js/blob/master/src/places/autocomplete.ts#L31), which supports a very limited set of types/filters for this API, which makes it impossible to use the method with the values from the aforementioned tables without tricking TypeScript with `as unknown as PlaceAutocompleteType` cast.

This contradicts the documentation of the endpoint, makes it impossible to use singular or combined values from the aforementioned tables and limits the capabilities of the autocompletion.

### Suggestion

If these capabilities of filtering by types are not to be deprecated by Google Maps API itself, I would suggest changing the type of `types` field to `string` to reach parity in filtering autocompletion predictions between raw API calls and this library.

I would also appreciate if anybody could suggest me another way to, for example, send `{ types: 'postal_code' }`, if there is one in this library and I'm not aware of it. It is supported in raw API calls and I see no reason why it should not be supported in the library.

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.