yuzhva / react-leaflet-markercluster

React wrapper of the official Leaflet.markercluster for react-leaflet
https://yuzhva.github.io/react-leaflet-markercluster/
MIT License
285 stars 99 forks source link

TypeScript definitions #54

Open high1 opened 6 years ago

high1 commented 6 years ago

Missing type definitions for TypeScript.

StazriN commented 6 years ago

How it looks with type definitions for TypeScript? When will it be supported please? Thanks

gwillz commented 5 years ago

Considering it only inherits MapLayer with no fancy whatever, something like this works:

declare module 'react-leaflet-markercluster' {
    import {MapLayer} from 'react-leaflet'
    export default class MarkerClusterGroup extends MapLayer {}
}

Edit: Don't forget, it's dependent on @types/react-leaflet.

silviuburceadev commented 3 years ago

I am using react-leaflet-markercluster 3.0.0-rc1 and @types/react-leaflet-markercluster 2.0.0 and I get this in the code:

'MarkerClusterGroup' cannot be used as a JSX component. Its instance type 'MarkerClusterGroup' is not a valid JSX element. Type 'MarkerClusterGroup' is missing the following properties from type 'ElementClass': render, context, setState, forceUpdate, and 3 more. TS2786

Code is very simple, used the example:

<MarkerClusterGroup>
  <Marker position={[49.8397, 24.0297]} />
  <Marker position={[52.2297, 21.0122]} />
  <Marker position={[51.5074, -0.0901]} />
</MarkerClusterGroup>

The index.d.ts clearly says that the definitions apply to v2.0, can we have something for 3.0.0?

Here is the definition for React Leaflet's FeatureGroup: export declare const FeatureGroup: import("react").ForwardRefExoticComponent<FeatureGroupProps & import("react").RefAttributes<LeafletFeatureGroup<any>>>; So I'm guessing that MarkerClusterGroup is something similar?

p.s. MapLayer is gone from React Leaflet v3 so it isn't as simple as @gwillz posted for v2.

nunos7 commented 2 years ago

Hi, what types do you use? I'm using "@types/react-leaflet-markercluster": "^3.0.0", and I have no way to set the events :(...