Skip to content

Commit

Permalink
fix: slots types missing when template only includes dynamic slots
Browse files Browse the repository at this point in the history
close #2233
  • Loading branch information
johnsoncodehk committed Dec 20, 2022
1 parent daa842f commit 70891a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vue-language-tools/vue-language-core/src/generators/script.ts
Expand Up @@ -417,7 +417,7 @@ export function generate(
codeGen.push(`InstanceType<typeof __VLS_publicComponent>['$emit']`);
}
codeGen.push(`,\n`);
if (htmlGen?.slotsNum) {
if (htmlGen?.hasSlot) {
codeGen.push(`children: ReturnType<typeof __VLS_template>,\n`);
}
else {
Expand All @@ -426,7 +426,7 @@ export function generate(
codeGen.push(`};\n`);
}
else {
if (htmlGen?.slotsNum) {
if (htmlGen?.hasSlot) {
usedTypes.WithTemplateSlots = true;
codeGen.push(`return {} as __VLS_WithTemplateSlots<typeof __VLS_publicComponent, ReturnType<typeof __VLS_template>>;\n`);
}
Expand Down
Expand Up @@ -75,7 +75,7 @@ export function generate(
const scopedClasses: { className: string, offset: number; }[] = [];
const blockConditions: string[] = [];

let slotsNum = 0;
let hasSlot = false;
let elementIndex = 0;

formatCodeGen.push('export { };\n');
Expand All @@ -96,18 +96,19 @@ export function generate(
cssCodeGen,
tagNames,
identifiers,
slotsNum,
hasSlot,
};

function declareSlots() {

codeGen.push(`declare var __VLS_slots:\n`);
for (const [exp, slot] of slotExps) {
hasSlot = true;
codeGen.push(`Record<NonNullable<typeof ${exp}>, (_: typeof ${slot.varName}) => any> &\n`);
}
codeGen.push(`{\n`);
for (const [name, slot] of slots) {
slotsNum++;
hasSlot = true;
writeObjectProperty(
name,
slot.loc, // TODO: SourceMaps.MappingKind.Expand
Expand Down
3 changes: 1 addition & 2 deletions vue-language-tools/vue-language-core/src/utils/localTypes.ts
Expand Up @@ -10,7 +10,6 @@ export function getTypesCode(
const libName = getVueLibraryName(vueVersion);
const slots = getSlotsPropertyName(vueVersion);
return `
import * as vue from '${libName}';
import type {
FunctionalComponent,
EmitsOptions,
Expand All @@ -36,7 +35,7 @@ export type GlobalComponents =
& PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
// @ts-ignore
& PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>
& Pick<typeof vue,
& Pick<typeof import('${libName}'),
// @ts-ignore
'Transition'
| 'TransitionGroup'
Expand Down

0 comments on commit 70891a6

Please sign in to comment.