sortablejs-vue3 icon indicating copy to clipboard operation
sortablejs-vue3 copied to clipboard

Support generic type parameters

Open ethanchristensen01 opened this issue 1 year ago • 3 comments

This update enables type checking scoped slots, and by extension, lets developers get type completions while writing the #item slot.

There is a "breaking change" to consider here: to access the type of the component, we can no longer use InstanceType<typeof sortable>, because it doesn't work with generic components. We have to replace InstanceType with ComponentExposed as described in this issue: Cannot use InstanceType<typeof Comp>> on generic components.

This requires adding 'vue-component-type-helpers' (from the official Vue Language Tools repository) as a dev dependency.

ethanchristensen01 avatar Sep 20 '24 23:09 ethanchristensen01

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sortablejs-vue3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 11:55pm

vercel[bot] avatar Sep 20 '24 23:09 vercel[bot]

Here's a screenshot of the type-hint you get in vs-code while hovering over the item slot of HelloWorld.vue. It automatically infers this from the type of the items parameter. image

ethanchristensen01 avatar Sep 21 '24 00:09 ethanchristensen01

@MaxLeiter I don't know if you saw this. It should be pretty quick to review if you're interested in taking a look.

ethanchristensen01 avatar Oct 10 '24 04:10 ethanchristensen01

Could this be improved by using defineSlots?

defineSlots<{
  item: (props: { element: GItem }) => any;
}>();

ffxsam avatar Feb 18 '25 18:02 ffxsam

BTW, I'm happy to update this PR with the latest improvements in Vue 3.5. But only if the maintainer(s) will actually merge this PR.

ffxsam avatar Feb 18 '25 18:02 ffxsam

Sorry for missing this. Thanks!

MaxLeiter avatar Aug 20 '25 04:08 MaxLeiter