Skip to content

Commit

Permalink
fix(language-core): component type narrowing in template not working
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Nov 29, 2023
1 parent 87473a9 commit dc2432f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 6 additions & 8 deletions packages/language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,14 @@ export function generate(
else {
codes.push(
`const ${var_originalComponent} = ({} as `,
`'${tag}' extends keyof typeof __VLS_ctx ? typeof __VLS_ctx : `,
);
for (const componentName of getPossibleOriginalComponentName(tag)) {
codes.push(`'${componentName}' extends keyof typeof __VLS_ctx ? `);
if (componentName === toCanonicalComponentName(tag)) {
codes.push(`typeof __VLS_ctx : `);
}
else {
codes.push(`{ [K in '${toCanonicalComponentName(tag)}']: typeof __VLS_ctx['${componentName}'] }: `);
}
codes.push(
`'${componentName}' extends keyof typeof __VLS_ctx ? `,
`{ '${toCanonicalComponentName(tag)}': typeof __VLS_ctx`,
...createPropertyAccessCode(componentName),
` }: `,
);
}
codes.push(
`typeof __VLS_resolvedLocalAndGlobalComponents)`,
Expand Down
15 changes: 8 additions & 7 deletions test-workspace/tsc/vue3/#3138/main.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script setup lang="ts">
import { defineAsyncComponent } from 'vue';
import { exactType } from 'tsc/shared';
const ReloadPrompt =
typeof window !== 'undefined'
? defineAsyncComponent(() => Promise.resolve({}))
: undefined;
declare const Child: undefined | (new () => {
$props: {
foo?(num: number): void;
};
});
</script>

<template>
<template v-if="ReloadPrompt">
<ReloadPrompt />
<template v-if="Child">
<Child :foo="num => exactType(num, {} as number)" />
</template>
</template>

0 comments on commit dc2432f

Please sign in to comment.