2

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

1 Answer 1

3

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:

https://stackblitz.com/edit/angular-bee8jg

Sign up to request clarification or add additional context in comments.

1 Comment

That answers my question. Thanks !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.