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

Typescript problems #51

Closed
christher-lenander opened this issue Oct 16, 2021 · 1 comment
Closed

Typescript problems #51

christher-lenander opened this issue Oct 16, 2021 · 1 comment

Comments

@christher-lenander
Copy link

christher-lenander commented Oct 16, 2021

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
Copy link
Collaborator

HusamElbashir commented Oct 21, 2021

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>>();

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

2 participants