Skip to content

Commit

Permalink
fix: intersect __VLS_slots with ...
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Dec 24, 2024
1 parent 210ac37 commit 0641670
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
}

function* generateSlots(options: TemplateCodegenOptions, ctx: TemplateCodegenContext): Generator<Code> {
const name = getSlotsPropertyName(options.vueCompilerOptions.target);

if (!options.hasDefineSlots) {
yield `var __VLS_slots!: `;
yield `var __VLS_slots!: typeof __VLS_ctx.${name} & `;
for (const { expVar, varName } of ctx.dynamicSlots) {
ctx.hasSlot = true;
yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${newLine}`;
Expand Down Expand Up @@ -85,8 +87,7 @@ function* generateSlots(options: TemplateCodegenOptions, ctx: TemplateCodegenCon
}
yield `}${endOfLine}`;
}
const name = getSlotsPropertyName(options.vueCompilerOptions.target);
yield `var ${name}!: typeof __VLS_ctx.${name} & typeof ${options.slotsAssignName ?? '__VLS_slots'}${endOfLine}`;
yield `var ${name}!: typeof ${options.slotsAssignName ?? '__VLS_slots'}${endOfLine}`;
}

function* generateInheritedAttrs(ctx: TemplateCodegenContext): Generator<Code> {
Expand Down
11 changes: 5 additions & 6 deletions test-workspace/tsc/passedFixtures/vue3/slots/main.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<template>
<!-- $slots type -->
{{ exactType($slots.foo, {} as Slot<{} | undefined> | undefined) }}

<!-- component slots type -->
<Comp value="1">
<template #foo="bindings">{{ exactType(bindings, {} as string) }}</template>
Expand Down Expand Up @@ -31,7 +28,7 @@
<script lang="ts">
export default {
name: 'Self',
slots: Object as SlotsType<{ foo?: {} }>
slots: Object as SlotsType<{ foo?: (_: any) => any }>
};
declare const Comp: new <T>(props: { value: T; }) => {
Expand All @@ -43,13 +40,15 @@ declare const Comp: new <T>(props: { value: T; }) => {
</script>

<script lang="ts" setup>
import { ref, type Slot, type SlotsType, useSlots, type VNode } from 'vue';
import { ref, type SlotsType, useSlots, type VNode } from 'vue';
import { exactType } from '../../shared';
const baz = ref('baz' as const);
const slots = useSlots();
exactType(slots, {} as {
exactType(slots, {} as Readonly<{
foo?(_: any): any
}> & {
bar?(_: { str: string; num: number; }): any;
} & {
baz?(_: { str: string; num: number; }): any;
Expand Down

0 comments on commit 0641670

Please sign in to comment.