Using an untyped Leaflet plugin in your TypeScript project
Leaflet has a prosperous ecosystem with hundreds of plugins. Most of them are not typed for TypeScript, however, with a minimal setup, you are able to use these plugins in your TypeScript mapping project.
Since TypeScript is definitely typed, a simple workaround is to provide a minimal type declaration file that can expose the plugin functions in the
The vector tile plugin Leaflet.VectorGrid isn’t officially typed and you are not able to directly use this plugin because the compiler doesn’t know its existence. So we just need to declare it with a
Then we are able to use the function in TypeScript
Here we go!
If we want to use more, we could continue to populate the type declaration file and maybe contribute it to the community when it becomes more complete.
For a fully functional exampe, see angular2-leaflet-starter.