diff --git a/.changeset/ninety-impalas-destroy.md b/.changeset/ninety-impalas-destroy.md new file mode 100644 index 000000000..a840bf8c7 --- /dev/null +++ b/.changeset/ninety-impalas-destroy.md @@ -0,0 +1,5 @@ +--- +'@vue-macros/volar': patch +--- + +support function component in v-slot diff --git a/packages/volar/src/jsx-directive.ts b/packages/volar/src/jsx-directive.ts index 0808c94e5..b9909e0b2 100644 --- a/packages/volar/src/jsx-directive.ts +++ b/packages/volar/src/jsx-directive.ts @@ -175,6 +175,13 @@ function transformVSlot({ }: TransformOptions & { nodes: import('typescript/lib/tsserverlibrary').JsxElement[] }) { + if (nodes.length === 0) return + codes.push(`type __VLS_getSlots = T extends new (...args: any) => any + ? InstanceType['$slots'] + : T extends (props: any, ctx: infer Ctx) => any + ? Ctx['slots'] + : any`) + nodes.forEach((node) => { if (!ts.isIdentifier(node.openingElement.tagName)) return @@ -296,7 +303,7 @@ function transformVSlot({ ',', ] ), - `} as InstanceType['$slots'] }`, + `} as __VLS_getSlots }`, ] as Segment[] if (attribute) { diff --git a/playground/vue3/src/examples/jsx-directive/v-slot/index.vue b/playground/vue3/src/examples/jsx-directive/v-slot/index.vue index d83d33f8b..d94d2d9d1 100644 --- a/playground/vue3/src/examples/jsx-directive/v-slot/index.vue +++ b/playground/vue3/src/examples/jsx-directive/v-slot/index.vue @@ -1,10 +1,23 @@