smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.02k stars 270 forks source link

TypeError: t3.trim is not a function coords.ts #379

Closed mugu-fatman closed 8 months ago

mugu-fatman commented 8 months ago

Hi , Thanks for the wonderful library , I am trying to use leaflet-geosearch in my svelte-kit application. but getting an this type error

coords.ts:4 Uncaught (in promise) TypeError: t3.trim is not a function
    at g (coords.ts:4:19)
    at NewClass.onSubmit (SearchControl.ts:396:20)
    at t3.handleClick (SearchControl.ts:224:16)
    at HTMLDivElement.onClick (resultList.ts:113:10)

I am using the searchControl as below

        const searchControl  = new GeoSearchControl({
            style: 'bar',
            provider: new OpenStreetMapProvider(),
            showMarker: true
        });

        map.addControl(searchControl);

using typescript version

"typescript": "^5.0.0",

mr339 commented 8 months ago

what was this closed? im also facing the same issue @mugu-fatman

gjvoosten commented 8 months ago

Same here: Screenshot from 2023-10-11 13-25-57

Downgrading to the previous version makes the error disappear. Please reopen or provide a reason why this was closed.

Note that the reason for the exception appears to be that validateCoords(query) is called with an undefined query, so this change would fix it:

diff --git a/src/coords.ts b/src/coords.ts
index b874b8e..e413608 100644
--- a/src/coords.ts
+++ b/src/coords.ts
@@ -1,7 +1,7 @@
 // @ts-nocheck

 export function validateCoords(query) {
-  const q = query.trim();
+  const q = query?.trim();
   const regex = /^(-?[0-9]*\.?\s*[0-9]*)\s*,?\s*(-?[0-9]*\.?[0-9]*)$/g;
   const match = regex.exec(q);
   if (match) {
mtmail commented 8 months ago

mugu-fatman closed it himself. It wasn't the library maintainer.

gjvoosten commented 8 months ago

I've opened a new issue #382 and PR #383

mugu-fatman commented 8 months ago

Thank you, There was already another issue opened for the same reason