Skip to content

Commit c5c025c

Browse files
Drop support for Vue 3.3 slots short definition (#3116)
1 parent 4f7f872 commit c5c025c

File tree

6 files changed

+13
-38
lines changed

6 files changed

+13
-38
lines changed

packages/vue-language-core/src/generators/script.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export function generate(
7878
mergePropDefaults: false,
7979
ConstructorOverloads: false,
8080
WithTemplateSlots: false,
81-
ToTemplateSlots: false,
8281
PropsChildren: false,
8382
};
8483

@@ -156,9 +155,6 @@ export function generate(
156155
`} };\n`,
157156
);
158157
}
159-
if (usedHelperTypes.ToTemplateSlots) {
160-
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]?: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
161-
}
162158
if (usedHelperTypes.PropsChildren) {
163159
codes.push(`type __VLS_PropsChildren<S> = { [K in keyof (boolean extends (JSX.ElementChildrenAttribute extends never ? true : false) ? never : JSX.ElementChildrenAttribute)]?: S; };\n`);
164160
}
@@ -385,22 +381,20 @@ export function generate(
385381
codes.push(`};\n`);
386382
}
387383
if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
388-
usedHelperTypes.ToTemplateSlots = true;
389384
usedHelperTypes.PropsChildren = true;
390-
codes.push(` & __VLS_PropsChildren<__VLS_ToTemplateSlots<`);
385+
codes.push(` & __VLS_PropsChildren<`);
391386
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
392-
codes.push(`>>`);
387+
codes.push(`>`);
393388
}
394389
codes.push(`;\n`);
395390
}
396391
else {
397392
codes.push(`const __VLS_props: {}`);
398393
if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
399-
usedHelperTypes.ToTemplateSlots = true;
400394
usedHelperTypes.PropsChildren = true;
401-
codes.push(` & __VLS_PropsChildren<__VLS_ToTemplateSlots<`);
395+
codes.push(` & __VLS_PropsChildren<`);
402396
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
403-
codes.push(`>>`);
397+
codes.push(`>`);
404398
}
405399
if (scriptSetupRanges.propsTypeArg) {
406400
codes.push(' & ');
@@ -685,10 +679,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
685679
generateConstNameOption();
686680

687681
if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) {
688-
usedHelperTypes.ToTemplateSlots = true;
689-
codes.push(`var __VLS_slots!: __VLS_ToTemplateSlots<`);
682+
codes.push(`var __VLS_slots!: `);
690683
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
691-
codes.push('>;\n');
684+
codes.push(';\n');
692685
};
693686

694687
codes.push(`function __VLS_template() {\n`);
@@ -875,10 +868,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
875868
if (!htmlGen) {
876869
codes.push(`// no template\n`);
877870
if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) {
878-
usedHelperTypes.ToTemplateSlots = true;
879-
codes.push(`let __VLS_slots!: __VLS_ToTemplateSlots<`);
871+
codes.push(`let __VLS_slots!: `);
880872
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
881-
codes.push(`>;\n`);
873+
codes.push(`;\n`);
882874
}
883875
else {
884876
codes.push(`const __VLS_slots = {};\n`);

packages/vue-test-workspace/vue-tsc/#2726/main.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { ref } from 'vue';
66
const foo = ref('bar');
77

88
defineSlots<{
9-
default: {
9+
default: (_: {
1010
foo: string;
1111
buz?: number;
12-
};
12+
}) => any;
1313
}>();
1414
</script>
1515

packages/vue-test-workspace/vue-tsc/#2758/main.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<script lang="ts" setup generic="T extends Record<string, string>">
1313
defineSlots<
1414
{
15-
[K in `cell:${string}`]: { value: T[keyof T] };
15+
[K in `cell:${string}`]?: (_: { value: T[keyof T] }) => any;
1616
} & {
17-
default: Record<string, any>;
17+
default?: (_: Record<string, any>) => any;
1818
}
1919
>();
2020
</script>

packages/vue-test-workspace/vue-tsc/components/main.vue

-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import ScriptSetupExpose from './script-setup-expose.vue';
66
import ScriptSetupTypeOnly from './script-setup-type-only.vue';
77
import ScriptSetupDefaultProps from './script-setup-default-props.vue';
88
import ScriptSetupGeneric from './script-setup-generic.vue';
9-
import ShortDefineSlots from './short-define-slots.vue';
109
1110
// https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits
1211
const ScriptSetupExact = defineComponent({
@@ -80,10 +79,4 @@ exactType(ScriptSetupExpose, ScriptSetupExposeExact);
8079
exactType(ScriptSetupTypeOnly, ScriptSetupTypeOnlyExact);
8180
exactType(ScriptSetupDefaultProps, ScriptSetupDefaultPropsExact);
8281
exactType(ScriptSetupGeneric, ScriptSetupGenericExact);
83-
exactType((new ShortDefineSlots()).$slots.foo, {} as ((props: {
84-
id: string;
85-
} | undefined) => any) | undefined);
86-
exactType((new ShortDefineSlots()).$slots.bar, {} as ((props: {
87-
id: number;
88-
}) => any) | undefined);
8982
</script>

packages/vue-test-workspace/vue-tsc/components/script-setup-generic.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
defineProps<{ foo: T }>();
33
defineEmits<{ (e: 'bar', data: T): void }>();
44
defineExpose({ baz: {} as T });
5-
defineSlots<{ default(data: T): any }>();
5+
defineSlots<{ default?(data: T): any }>();
66
</script>
77

88
<script lang="ts">

packages/vue-test-workspace/vue-tsc/components/short-define-slots.vue

-10
This file was deleted.

0 commit comments

Comments
 (0)