Skip to main content

Working with typescript

The GeoApps API and all related components are written in Typescript. To provide better support to build apps with the API that are also based on typescript, we provide typings in an npm-package that can be used in your own project.

Installating the typings

The typings package can be installed directly from npm using the following command, which installs the package as a development dependency:

npm i -D @mapgear/geoapps

Remark: it is still necessary to include the javascript references from your tenant. We do not provide access (yet) through the API in the form of an NPM package.

Using the typings

To use the typings on the geoapps-object, the best way is to cast the window first to our GeoAppsWindow-class, that provides access to the typed geoapps object. Any variable that is derived later on from this class will directly have the correct typings.

import { GeoAppsWindow } from "@mapgear/geoapps";

const geoapps = (window as unknown as GeoAppsWindow).geoapps;

The cast to unknown is necessary to allow a recast to our custom interface, otherwise Typescript will set an error.