I have a JS library called leaflet which has an existing TypeScript definition file.
I wish to use a plugin which extends some of the objects in leaflet with an extra function.
In the existing TypeScript definition file the objects are defined as classes rather than interfaces.
e.g.
declare module L {
function circleMarker(latlng: LatLng, options?: PathOptions): CircleMarker;
export class CircleMarker extends Circle {
constructor(latlng: LatLng, options?: PathOptions);
setLatLng(latlng: LatLng): CircleMarker;
setRadius(radius: number): CircleMarker;
toGeoJSON(): any;
}
}
If I try and define it a second time in a separate file then I get an error about "Duplicate Identifier 'CircleMarker'.".
declare module L {
export class CircleMarker {
bindLabel(name: string, options: any): CircleMarker;
}
}
This makes sense as it's a class and not an interface, but that being the case is there a way to extend this class definition without changing the original definition file?
The base definition file is pulled in from DefinitelyTyped via nuget so I have a very strong desire not to make any changes to it as it'll make updating much more awkward/prone to failure.
CircleMarkerclass isn't aninterface, so I don't see how it's relevant. The challenge is that interfaces are just compile time checks in TypeScript, so it's possible to "extend" them. However, classes are an actual JavaScript construct, and far more complex to extend cleanly and consistently. - WiredPrairie