vue.draggable.next icon indicating copy to clipboard operation
vue.draggable.next copied to clipboard

Improve typescript support on slots

Open SimonSimCity opened this issue 3 years ago • 1 comments

This repo has already some typescript definitions, but one I'm particularly missing is the typing of variables passed to a slot.

<draggable v-model="myArray" item-key="id">
  <template #item="{element}">
    <!-- "element" in here is of type "any", even though myArray has defined type in my case -->
    <div>{{element.name}}</div>
   </template>
</draggable>

Having types is really important for us as it prevents a lot of bugs.

Avoiding using properties passed in as parameters on the slot would work around this issue already - keeping it as it was on the previous implementation, where I had to use v-for inside the slot...

SimonSimCity avatar Apr 28 '22 10:04 SimonSimCity

@greenhat616 References https://stackoverflow.com/a/72916031/13621750

you can custom slot type like this
<template #item="{ element } : { element: CustomType }">

image

moreant avatar Oct 13 '22 07:10 moreant