Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export types for Typescript implementations #177

Open
charlieforward9 opened this issue Jun 23, 2023 · 3 comments
Open

Export types for Typescript implementations #177

charlieforward9 opened this issue Jun 23, 2023 · 3 comments

Comments

@charlieforward9
Copy link

charlieforward9 commented Jun 23, 2023

I would like to have the ability to declare the DrawEvents type in my TS function, for safe scaling and intellisense.

import { DrawEvents } from "react-leaflet-draw";
 
const onEvent = (event: DrawEvents) => {
  ...
}

Throws: Module '"react-leaflet-draw"' declares 'DrawEvents' locally, but it is not exported.

I assume as I continue to develop, I will need access to more types, so it would be nice to have them all available, just in case.

@sheldonmaschmeyer
Copy link

sheldonmaschmeyer commented Jul 4, 2023

I agree. As a workaround, for now, below is an example of using leaflet for the type definition.

import type L from 'leaflet';
const onCreate = (e: L.DrawEvents.Created): void => {
setDrafts([
    ...drafts,
    {
      id: e.layer._leaflet_id,
      layer: JSON.stringify(e.layer.toGeoJSON()),
    },
  ]);
}

in a *.d.ts file

import type L from 'leaflet';

declare module 'leaflet' {
  ...
  export interface Layer {
    _layers: L.Layers;
    _leaflet_id: number;
  }
}

@SheldonWBM
Copy link

SheldonWBM commented Sep 7, 2023

Update to workaround (after updating packages):

declare module 'leaflet' {
...
  export interface DrawEvents {
    Created: {
      layer: LayerGroup;
    };
    Edited: {
      layers: L.Layers;
    };
  }
  export interface Layer {
    _layers: L.Layers;
    _leaflet_id: number;
  }
}

then instead of const onCreate = (e: L.DrawEvents.Created): void => {
it is const onCreate = (e: L.DrawEvents['Created']): void => {

I agree with @charlieforward9 , there must be a better solution.

@TheNumenorean
Copy link

TheNumenorean commented Nov 4, 2023

Bump, this would be really nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants