-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Closed
Description
- I tried using the
@types/leafletpackage and had problems. - I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
- I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
- Mention the authors (see
Definitions by:inindex.d.ts) so they can respond.- Authors: @alejo90
I'm trying to add a handler to my Leaflet map (actually, I'm trying to manually add a Leaflet draw handler to a map without using it's toolbar), and I'm running into a syntax issue with the addHandler method in L.Map. I'm using TypeScript 2.3.
This is the line in question:
addHandler(name: string, HandlerClass: () => Handler): this; // HandlerClass is actually a constructor function, is this the right way?
Following the example here, I have the following line of code:
this.map.addHandler('polygon', L.Draw.Polygon);
But that gives me the following error:
Argument of type 'typeof Polygon' is not assignable to parameter of type '() => Handler'.
If I change the addHandler line in index.d.ts to:
addHandler(name: string, HandlerClass: typeof Handler): this;
Then the error goes away, and everything works perfectly. Plus, it matches the examples in Leaflet's own documentation.
It seems like the following could be possible, too, no? That's got to be at least a little bit better than any.
export class Class {
static extend(props: any): typeof Class;
static include(props: any): typeof Class;
static mergeOptions(props: any): typeof Class;
static addInitHook(initHookFn: () => void): typeof Class;
}
Metadata
Metadata
Assignees
Labels
No labels