I'm trying to get Leaflet and a plugin to work together in an Ionic 2 project. I've installed and imported Leaflet itself and the leaflet-path-transform plugin, along with the Leaflet type declaration included in DefinatelyTyped. The code all works if I add declare var L: any;
to ignore the type declarations.
This is the important parts of the page controller (home.ts):
var polyline = new L.Polyline(
L.GeoJSON.coordsToLatLngs([
[114.14314270019531, 22.49479484975443],
[114.21798706054688, 22.524608511026262],
[114.20768737792969, 22.524608511026262],
[114.20768737792969, 22.536024805886974]
]), {
weight: 15,
draggable: true,
transform: true
})
.bindPopup("L.Polyline")
.addTo(map);
polyline.transform.enable();
draggable
and transform
aren't valid options in basic Leaflet (nor is .transform
), so I wrote a type declaration file at PROJECT_DIR\node_modules\@types\leaflet-path-transform\index.d.ts
to define them. What I've written so far is based on the type declaration for leaflet-editable, since that plugin allows for new MapOptions when creatingthe L.Map object.
/// <reference types="leaflet" />
declare namespace L {
export interface Polyline {
draggable: boolean;
}
namespace Polyline {
export interface PolylineOptions {
draggable: boolean;
}
}
}
This only addresses the first option so far, but it hasn't succeeded in clearing the TypeScript error:
Typescript Error
Argument of type '{ weight: number; draggable: boolean; }' is not assignable to parameter of type 'PolylineOptions'. Object literal may only specify known properties, and 'draggable' does not exist in type 'PolylineOptions'.
Can someone help me figure out what I'm doing wrong here? At first I thought that the new type declaration file was simply being ignored, but if I leave a typo in it, it triggers new errors, so it does seem to have an effect.
In case it helps, here's the environment I'm working in:
- Ionic Framework: 2.0.0
- Ionic Native: 2.4.1
- Ionic App Scripts: 1.0.0
- Angular Core: 2.2.1
- Angular Compiler CLI: 2.2.1
- Node: 6.9.4
- OS Platform: Windows 10
- Navigator Platform: Win32
- User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36