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

[@types/leaflet] geoJSON() complains about arrays while documentation states they are valid #60930

Closed
ma7moudat opened this issue Jun 23, 2022 Discussed in #60818 · 3 comments

Comments

@ma7moudat
Copy link

ma7moudat commented Jun 23, 2022

Discussed in #60818

Originally posted by ma7moudat June 15, 2022
The official Leaflet documentation states:

GeoJSON objects may also be passed as an array of valid GeoJSON objects.

However, when using Typescript, it complains when an array is passed to geoJSON():

import {geoJSON} from "leaflet";
import {LineString} from "geojson";

const myLines: LineString[] = [{
  "type": "LineString",
  "coordinates": [[-100, 40], [-105, 45], [-110, 55]]
}, {
  "type": "LineString",
  "coordinates": [[-105, 40], [-110, 45], [-115, 55]]
}];

// this cuases an error, eventhough it shouldn't:
// TS2345: Argument of type 'LineString[]' is not assignable to parameter of type 'GeoJsonObject'. 
// Property 'type' is missing in type 'LineString[]' but required in type 'GeoJsonObject'.
geoJSON(myLines);

// this works, but should not be needed
const myLinesLayer = geoJSON(undefined)
myLines.forEach((line) => myLinesLayer.addData(line))
someonewithpc added a commit to someonewithpc/DefinitelyTyped that referenced this issue Jul 20, 2022
@someonewithpc
Copy link
Contributor

Fixed by #61339

@asamad-hitachi
Copy link

Hi
I am facing similar issue
I raised it to react-leaflet but they suggested to raise it here.

Issue link : https://github.com/PaulLeCam/react-leaflet/issues/1015#issue-1331955818

Please provide me any suggestions to what I should do to resolve this.
It would be great help.

someonewithpc added a commit to someonewithpc/DefinitelyTyped that referenced this issue Aug 17, 2022
someonewithpc added a commit to someonewithpc/DefinitelyTyped that referenced this issue Aug 17, 2022
@ma7moudat
Copy link
Author

@asamad-hitachi until you get the fix, you can create a leaflet.d.ts file in your project with the following content:

// fix leaflet's geoJSON type definition
// todo remove after github issue has been resolved
// @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/60930
import { GeoJsonObject } from 'geojson'
import { GeoJSON } from 'leaflet'

declare module 'leaflet' {
    function geoJSON<P = never>(
        geojson?: GeoJsonObject | GeoJsonObject[],
        options?: GeoJSONOptions<P>
    ): GeoJSON<P>
}

typescript-bot pushed a commit that referenced this issue Sep 15, 2022
…ds, as of version 1.8 by @someonewithpc

* Leaflet: Update definitions to include missing methods found in 1.8

A declaration was generated with `dts-gen` and compared with the existing
definition, merging them manually to add missing methods

* Leaflet: Explicitly define `Evented.listens` with the corresponding function type and fix linter errors

* Leaflet: Add tests for added methods

* Leaflet: Add missing Mixin export

* Allow L.geoJSON to accept geojson.GeoJsonObject[], fixing #60930

* Temporarily duplicate the implementation of Events and Evented, so tests pass

* Fix toGeoJson(precision?: number | false) argument for all overrides

* Add missing properties, as pointed out by DangerBotOSS

* Add a 'tileabort' event when a tile load is cancelled

See Leaflet/Leaflet#6786

* Make changes reported in Leaflet's Changelog

  - Make DivOverlay / Tooltip interactive (#7531, #7532 by @johnd0e)
  - Add openOn, close, toggle functions to DivOverlay (#6639 by @johnd0e)
  - Introduce DomEvent.off(el) to remove all listeners (#7125 by @johnd0e)
  - Allow preventing round-off errors by passing false to Util.formatNum / toGeoJSON (#7100 by @johnd0e)
  - Add autoPanOnFocus to Marker (#8042 by @IvanSanchez)
  - Add referrerPolicy to TileLayer (#7945 by @natevw)
  - Add playsInline to VideoOverlay (#7928 by @Falke-Design)
  - Add getCenter to ImageOverlay (#7848 by @Falke-Design)
  - Fire a tileabort event when a TileLayer load is cancelled (#6786 by @dstndstn)
  - Add crossOrigin to Icon (#7298 by @syedmuhammadabid)
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