Skip to content

Commit

Permalink
fix: allow slots to have no arguments (#3376)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <johnsoncodehk@gmail.com>
  • Loading branch information
so1ve and johnsoncodehk authored Jul 13, 2023
1 parent 960b29c commit fb501c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vue-language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,14 +1596,15 @@ export function generate(

if (hasScriptSetupSlots) {
codes.push(
'__VLS_normalizeSlot(',
['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly],
'__VLS_slots[',
['', 'template', node.loc.start.offset, capabilitiesPresets.diagnosticOnly],
slotNameExpNode?.content ?? `('${getSlotName()}' as const)`,
['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly],
']',
['', 'template', node.loc.end.offset, capabilitiesPresets.diagnosticOnly],
'?.(',
')?.(',
['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly],
'{\n',
);
Expand Down
1 change: 1 addition & 0 deletions packages/vue-language-core/src/utils/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K
>;
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
declare function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
declare function __VLS_componentProps<T, K>(comp: T, fnReturn: K):
__VLS_PickNotAny<K, {}> extends { __ctx: { props: infer P } } ? NonNullable<P>
: T extends (props: infer P, ...args: any) => any ? NonNullable<P> :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
defineSlots<{
content(): any;
prop(props: { foo: string }): any;
}>();
</script>

<template>
<slot name="content" />
<slot name="prop" :foo="''" />
</template>

0 comments on commit fb501c2

Please sign in to comment.