vue-select icon indicating copy to clipboard operation
vue-select copied to clipboard

[Vue3, Typescript] how to properly type v-slot:option?

Open petegriffith opened this issue 4 years ago • 6 comments

When I use a template to custom render one or several options like so:

image

typescript infers country to be VNode[] | undefined

It then yells at me that country doesn't have alpha_2 or country_name properties - rightly so, as it thinks country is at best a VNode[]

Thing is, countriesObj is correctly typed, so v-slot:options is where the inference is getting lost. I have tried a bunch of things to retype country but nothing seems to sufficiently overlap with the type VNode[]

Any thoughts? Is this a package issue or a Vue issue?

Thanks

petegriffith avatar Nov 19 '21 04:11 petegriffith

Encountered this too, even if you type country explicitly, it yells that it's not compatible with VNode[]

<!-- country is still underlined here, saying that Country is not compatible with VNode[] -->
<template v-slot="country: Country">

The only thing that works for me is to type it as any and the error goes away (but I lose all typing)

<template v-slot="country: any">

Papooch avatar Nov 30 '21 14:11 Papooch

Just to chime in that this is still ongoing, and that I'm also experiencing the same

cpotey avatar Mar 24 '22 17:03 cpotey

This is wotking for me:

<!-- Bar.vue -->
<div>
  <slot name="default" :resizeBar="resizeBar"></slot>
</div>

<!-- Parrent.vue -->
<div>
  <template #default="{ resizeBar }">
    <div @click="() => resizeBar()">
        Close
    </div>
  </template>
</div>

NisuSan avatar Sep 16 '22 17:09 NisuSan

@NisuSan The issue is the type of the slot variables

tvld avatar Oct 29 '22 11:10 tvld

found this which seems to be working like charm https://stackoverflow.com/a/71849231/7369310

<template #default="{country} : {country: TCountry}">
  {{ country.name }}
</template>

heysaad avatar Feb 23 '23 19:02 heysaad