I am using Leaflet Library ( http://leafletjs.com ) in a TypeScript project.
I am displaying marker on the map that are configured using options: http://leafletjs.com/reference-1.3.0.html#marker-l-marker
I am trying to use this library in my project: https://github.com/bbecquet/Leaflet.RotatedMarker
I am trying to add more options to second argument of Marker but I am getting typescript errors:
ERROR in src/app/app.component.ts(61,7): error TS2345: Argument of type '{ rotationAngle: number; }' is not assignable to parameter of type 'MarkerOptions'.
Object literal may only specify known properties, and 'rotationAngle' does not exist in type 'MarkerOptions'
I trying to create a typings script or file to allow me do that.
/// <reference types="leaflet" />
declare module L {
export interface MarkerOptions {
rotationAngle: number;
rotationOrigin: string;
}
}
May be something similar to this: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/leaflet/index.d.ts#L1470
What am I missing to make this work ?
How to create custom typings for JavaScript code or third party library that doesn't provide typings out of the box ?
Here is an MCVE: https://github.com/badis/typescript-stackoverflow-question
You have to install types:
@types/leaflet-rotatedmarker
Also, include the libraries in your component:
import L from 'leaflet';
import 'leaflet-rotatedmarker';
Here is a working project with no typing error:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.