From c6bb0bf572ddd34b4de249e32915f9cb5ebe0aa2 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Fri, 9 Dec 2022 05:36:39 +0800 Subject: [PATCH] feat: pretty component type emit with template slots type close #2161 --- .../vue-language-core/src/generators/script.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vue-language-tools/vue-language-core/src/generators/script.ts b/vue-language-tools/vue-language-core/src/generators/script.ts index d286ed49e6..573cd84505 100644 --- a/vue-language-tools/vue-language-core/src/generators/script.ts +++ b/vue-language-tools/vue-language-core/src/generators/script.ts @@ -37,6 +37,7 @@ export function generate( DefinePropsToOptions: false, mergePropDefaults: false, ConstructorOverloads: false, + WithTemplateSlots: false, }; writeScriptSrc(); @@ -118,6 +119,9 @@ export function generate( codeGen.push(genConstructorOverloads('__VLS_ConstructorOverloads')); } } + if (usedTypes.WithTemplateSlots) { + codeGen.push(`type __VLS_WithTemplateSlots = T & { new(): { $slots: S } };\n`); + } } function writeScriptSrc() { if (!sfc.script?.src) @@ -422,11 +426,13 @@ export function generate( codeGen.push(`};\n`); } else { - codeGen.push(`return {} as typeof __VLS_publicComponent`); if (htmlGen?.slotsNum) { - codeGen.push(` & { new (): { $slots: ReturnType } }`); + usedTypes.WithTemplateSlots = true; + codeGen.push(`return {} as __VLS_WithTemplateSlots>;\n`); + } + else { + codeGen.push(`return {} as typeof __VLS_publicComponent;\n`); } - codeGen.push(`;\n`); } codeGen.push(`};\n`); codeGen.push(`return {} as typeof __VLS_setup extends () => Promise ? T : never;\n`);