vueform / multiselect

Vue 3 multiselect component with single select, multiselect and tagging options (+Tailwind CSS support).
https://vueform.com
MIT License
808 stars 151 forks source link

Property 'select' does not exist on type 'Multiselect' #287

Closed cnakh closed 1 year ago

cnakh commented 2 years ago

I use with Vue 3 with TypeScript as code below

<template>
    <Multiselect
          valueProp="id"
          label="name"
          :options="getCategories"
          :searchable="true"
          ref="selectCategory"
    />
</template>

<script setup lang="ts">
import Multiselect from "@vueform/multiselect";
...
const selectCategory = ref<InstanceType<typeof Multiselect>>();
...
</script>

When I call select method it work fine in development, but when I build it get error

selectCategory.value.select(data);
Property 'select' does not exist on type 'Multiselect'.
n14s commented 1 year ago

I'm also interested to know how to use the API with Vue3 composition API and script setup

antpngl92 commented 1 year ago

I had a similar error trying to access selectCategory.value.isOpen boolean.

To fix that I created a mock ref type:

type MultiselectRef = InstanceType<typeof Multiselect> & {
  isOpen: boolean;
}

in your case will be

type MultiselectRef = InstanceType<typeof Multiselect> & {
  select: (data: object | string | whatever) => void;
}

@adamberecz Perhaps a type definition with all attributes of the ref object would fix further similar issues?

adamberecz commented 1 year ago

Could anyone reliably help me with TS issues to put everything in place once and for all in both Vue 2 & 3? If so, please let me know!

antpngl92 commented 1 year ago

Could anyone reliably help me with TS issues to put everything in place once and for all in both Vue 2 & 3? If so, please let me know!

I can do it, will open a PR at some point today.

tholu commented 1 year ago

@antpngl92 Thanks for your PR! @adamberecz Can this be merged anytime soon?

Edit: I have referenced the wrong component, works now.

crobinson-expl commented 1 year ago

This PR fixes an issue I'm having with TypeScript and the open API method. @adamberecz, what is preventing the PR from being approved and merged?

adamberecz commented 1 year ago

This should now be fixed in 2.6.3. Let me know if you still encounter any issues. Thanks for the patience. 🙏

crobinson-expl commented 1 year ago

This should now be fixed in 2.6.3. Let me know if you still encounter any issues. Thanks for the patience. 🙏

Thanks, @adamberecz!