Leaflet Types for Angular👩‍💻

When developing angular applications that use leaflet, you can run into some issues. 💣

Perhaps you are trying to import leaflet like this

import * as L from 'leaflet';

One of the most common issues (perhaps when developing with later versions of angular which use strict typescript rules by default) is you run into an error where you receive the error:

💣leaflet-src.js’ implicitly has an ‘any’ type.

When trying to remind myself of the solution, I came across this article:

https://medium.com/runic-software/the-simple-guide-to-angular-leaflet-maps-41de83db45f1

Indeed this was the solution!

This means that you can install the types like so:

npm install --save @types/leaflet

Then you can use the types direct from leaflet, giving you a better typescript experience! Like this:

import {Map} from 'leaflet';


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *