inocan-group / vue3-google-map

A set of composable components for easy use of Google Maps in your Vue 3 projects.
https://vue3-google-map.com
MIT License
280 stars 57 forks source link

Typescript problems #51

Closed christher-lenander closed 2 years ago

christher-lenander commented 2 years ago

Hello!

First I want to say awesome lib.

I using typescript and whren I trying to use map ref by doing ref="mapRef".

Linting complains that ready doesn't exist on type never.

const panToAndZoom = (position: LatLng) => {
  if (mapRef.value?.ready) {
    mapRef.value.map.panTo(position);
    mapRef.value.map.setZoom(15);
  }
};

To get it to work I had to to like this.

const panToAndZoom = (position: LatLng) => {
  const gmap = mapRef.value as InstanceType<typeof GoogleMap> | null;

  if (gmap?.ready) {
    gmap.map?.panTo(position);
    gmap.map?.setZoom(15);
  }
};
HusamElbashir commented 2 years ago

Hi @ChristherLenander I don't think there's a way around this. You can probably just declare your ref in a nicer way like this:

const mapRef = ref<InstanceType<typeof GoogleMap>>();