@googlemaps/typescript-guards
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

Google Maps TypeScript Guards

npm Build Release codecov GitHub contributors semantic-release Discord

Description

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.

Documentation

For the complete API check the reference documentation.

Install

Available via npm as the package @googlemaps/typescript-guards.

npm i @googlemaps/typescript-guards

Example

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();
}

Readme

Keywords

Package Sidebar

Install

npm i @googlemaps/typescript-guards

Weekly Downloads

19,089

Version

2.0.3

License

Apache-2.0

Unpacked Size

24.9 kB

Total Files

11

Last publish

Collaborators

  • kenough
  • wangela
  • google-wombot