This package provides TypeScript guards for the Google Maps JavaScript API.
A type guard (or type predicate) is an expression that performs a runtime check that guarantees the type in some scope. Type guards are used to narrow the type of a variable or parameter.
- Sign up with Google Maps Platform
- A Google Maps Platform project with the Maps Javascript API enabled
- An API key associated with the project above
- Node.js and NPM
Available via npm as the package @googlemaps/typescript-guards.
npm i @googlemaps/typescript-guards
For the complete API check the documentation.
The following example narrows a union type google.maps.LatLng | google.maps.LatLngLiteral
to google.maps.LatLngLiteral
using the isLatLngLiteral
guard.
import { isLatLngLiteral } from "@googlemaps/typescript-guards";
const latLng: google.maps.LatLng | google.maps.LatLngLiteral = ...;
if (isLatLngLiteral(latLng)) {
lat = latLng.lat;
lng = latLng.lng;
} else {
lat = latLng.lat();
lng = latLng.lng();
}
Contributions are welcome and encouraged! If you'd like to contribute, send us a pull request and refer to our code of conduct and contributing guide.
This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to the Google Maps Platform Terms of Service.
This library is not a Google Maps Platform Core Service. Therefore, the Google Maps Platform Terms of Service, e.g., Technical Support Services Guidelines, Service Level Agreement "SLA", and Deprecation Policy, do not apply to the code in this library.
This library is offered via an open source license. It is not governed by the Google Maps Platform Support Technical Support Services Guidelines, the SLA, or the Deprecation Policy. However, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service.
This library adheres to semantic versioning to indicate when backwards-incompatible changes are introduced. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.
If you find a bug, or have a feature request, please file an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of our developer community channels. If you'd like to contribute, please check the contributing guide.
You can also discuss this library on our Discord server.