Skip to content

Commit

Permalink
feat: pretty component type emit with template slots type
Browse files Browse the repository at this point in the history
close #2161
  • Loading branch information
johnsoncodehk committed Dec 8, 2022
1 parent 9244174 commit c6bb0bf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vue-language-tools/vue-language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function generate(
DefinePropsToOptions: false,
mergePropDefaults: false,
ConstructorOverloads: false,
WithTemplateSlots: false,
};

writeScriptSrc();
Expand Down Expand Up @@ -118,6 +119,9 @@ export function generate(
codeGen.push(genConstructorOverloads('__VLS_ConstructorOverloads'));
}
}
if (usedTypes.WithTemplateSlots) {
codeGen.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): { $slots: S } };\n`);
}
}
function writeScriptSrc() {
if (!sfc.script?.src)
Expand Down Expand Up @@ -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<typeof __VLS_template> } }`);
usedTypes.WithTemplateSlots = true;
codeGen.push(`return {} as __VLS_WithTemplateSlots<typeof __VLS_publicComponent, ReturnType<typeof __VLS_template>>;\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<infer T> ? T : never;\n`);
Expand Down

0 comments on commit c6bb0bf

Please sign in to comment.