# @googlemaps/typescript-guards

> TypeScript guards for Google Maps Platform JavaScript.

Latest version **2.0.3** (published 2022-09-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @googlemaps/typescript-guards
pnpm add @googlemaps/typescript-guards
yarn add @googlemaps/typescript-guards
bun add @googlemaps/typescript-guards
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2022-09-26 |
| First published | 2021-11-11 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Justin Poehnelt |
| Maintainers | jpoehnelt, google-wombot |
| Keywords | google, maps, typescript |

## Links

- npm: https://www.npmjs.com/package/@googlemaps/typescript-guards
- Repository: https://github.com/googlemaps/js-typescript-guards
- Issues: https://github.com/googlemaps/js-typescript-guards/issues
- npm.io page: https://npm.io/package/@googlemaps/typescript-guards

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2022-09-26
- 2.0.2 — 2022-08-15
- 2.0.1 — 2022-07-04
- 2.0.0 — 2022-05-25
- 1.0.16 — 2022-05-17
- 1.0.15 — 2022-05-10
- 1.0.14 — 2022-04-22
- 1.0.13 — 2022-04-12
- 1.0.12 — 2022-04-01
- 1.0.11 — 2022-03-24
- 1.0.10 — 2022-03-15
- 1.0.9 — 2022-03-04
- 1.0.8 — 2022-02-23
- 1.0.7 — 2022-02-15
- 1.0.6 — 2022-02-07
- … 6 more at https://npm.io/package/@googlemaps/typescript-guards/versions

## README

# Google Maps TypeScript Guards

[![npm](https://img.shields.io/npm/v/@googlemaps/typescript-guards)](https://www.npmjs.com/package/@googlemaps/typescript-guards)
![Build](https://github.com/googlemaps/js-typescript-guards/workflows/Test/badge.svg)
![Release](https://github.com/googlemaps/js-typescript-guards/workflows/Release/badge.svg)
[![codecov](https://codecov.io/gh/googlemaps/js-typescript-guards/branch/main/graph/badge.svg)](https://codecov.io/gh/googlemaps/js-typescript-guards)
![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/js-typescript-guards?color=green)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Discord](https://img.shields.io/discord/676948200904589322?color=6A7EC2&logo=discord&logoColor=ffffff)](https://discord.gg/jRteCzP)

## Description

This package provides [TypeScript guards](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) 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](https://googlemaps.github.io/js-typescript-guards/index.html).

## Install

Available via npm as the package [@googlemaps/typescript-guards](https://www.npmjs.com/package/@googlemaps/typescript-guards).

```sh
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.

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

---
_Source: https://npm.io/package/@googlemaps/typescript-guards · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
