[New Feature] Background Geolocation Typescript API

Transistor Software
2 min readOct 19, 2018

--

The Background Geolocation SDK for both Cordova and React Native now provides its own comprehensive Typescript API.

Cordova

Up until now, in order to use the SDK with Ionic, you had to fetch a reference from the window object:

let bgGeo = (<any>window).BackgroundGeolocation;

No more: assuming the plugin has been added to node_modules (which $ ionic cordova plugin add... already does), you can now simply import it:

import BackgroundGeolocation from "cordova-background-geolocation"

React Native

From here on, the API for both React Native and Cordova are identical. They both share the same typescript definitions, so going forward from here, the only difference is where you import "it" from.

Interfaces

Import interfaces as needed. On event-callbacks, for example:

Documentation

All the SDK’s documentation has been migrated from the old markdown files into the definition.d.ts files themselves, making it possible to auto-generate them using Typedoc and published to transistorsoft.github.io:

Document-management is much simpler now and docs themselves more enjoyable to write with the easy linking throughout the API. Typedoc’s templating system is great and I’m importing my own custom template. The docs are sure to evolve from here on.

Code-assist

Now you have code-assist. For example, start typing "BackgroundGeolocation.get

Since the docs have been migrated into the SDK’s Typescriptdefinitions.d.ts, a snippet of the docs will appear on hovering members, such as distanceFilter:

Method / event signatures:

--

--

Transistor Software

Creator of Background Geolocation SDK. Professional plugin developers — geolocation specialists. https://www.transistorsoft.com