Skip to content

Commit

Permalink
fix(volar): support defineSlots for the latest Volar
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 24, 2023
1 parent 76322d6 commit dd3ea8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-pots-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/volar': patch
---

support `defineSlots` for the latest Volar
6 changes: 3 additions & 3 deletions packages/volar/src/define-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const transform = ({

replace(
embeddedFile.content,
'return __VLS_slots',
`return __VLS_slots as __VLS_DefineSlots<`,
/var __VLS_slots!: .*/,
'var __VLS_slots!: __VLS_DefineSlots<',
(): Segment<FileRangeCapabilities> => [
// slots type
sfc.scriptSetup!.content.slice(typeArg.pos, typeArg.end),
Expand All @@ -40,7 +40,7 @@ const transform = ({
'>'
)
embeddedFile.content.push(
`type __VLS_DefineSlots<T> = { [SlotName in keyof T]: (_: T[SlotName]) => any }`
`type __VLS_DefineSlots<T> = { [SlotName in keyof T]: T[SlotName] extends Function ? T[SlotName] : (_: T[SlotName]) => any }`
)
}

Expand Down
11 changes: 4 additions & 7 deletions playground/vue3/src/examples/define-slots/child.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ interface Slots {
title: {
foo: 'foo' | boolean
}
default: {
bar: 'bar' | number
}
default: (scope: { bar: 'bar' | number }) => any
}
defineSlots<Slots & { title: never }>()
defineSlots<Slots>()
</script>

<template>
<div>defineSlots</div>
<div>
<slot name="title" foo="bar">title</slot>
</div>
<slot name="title" foo="foo">title</slot>
<slot name="default" bar="bar">title</slot>
</template>

0 comments on commit dd3ea8d

Please sign in to comment.