Skip to content

Commit

Permalink
fix: expose props type in return for generic component
Browse files Browse the repository at this point in the history
close #2639
  • Loading branch information
johnsoncodehk committed Apr 21, 2023
1 parent 5a9f46d commit 184cce1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vue-language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export function generate(
codes.push('emit: typeof __VLS_emit');
codes.push('};\n');
codes.push('})(),\n');
codes.push(') => ({} as any))');
codes.push(') => ({} as import("vue").VNode & { __props?: typeof __VLS_props, __ctx?: typeof __VLS_ctx }))');
}
else if (!sfc.script) {
// no script block, generate script setup code at root
Expand Down
37 changes: 37 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#2639/Bar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<Foo :items="items">
<template #content="{ item }">
<div>{{ item.name }}</div>
</template>
</Foo>
</template>

<script setup lang="ts">
import Foo from './Foo.vue';
type ShowCaseItem = {
name: string;
icon: string;
action: () => void;
index: number;
};
const items: ShowCaseItem[] = [
{
name: 'Instagram Follow Up',
action: () => {
console.log('open IG');
},
icon: 'instagramIcon',
index: 0,
},
{
name: 'Email Follow Up',
action: () => {
console.log('open email');
},
icon: 'envelopeIcon',
index: 1,
},
]
</script>
11 changes: 11 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#2639/Foo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div v-for="item in props.items" :key="item.index" >
<slot :item="item" name="content" />
</div>
</template>

<script setup lang="ts" generic="T extends {index: number}">
const props = defineProps<{
items: T[];
}>();
</script>
2 changes: 1 addition & 1 deletion packages/vue-test-workspace/vue-tsc/components/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ declare const ScriptSetupGenericExact: <T, >(
emit: { (e: 'bar', data: T): void },
expose(_exposed: { baz: T }): void,
}
) => any;
) => import('vue').VNode & { __props?: typeof _props, __ctx?: typeof _ctx };
exactType(ScriptSetup, ScriptSetupExact);
exactType(ScriptSetupExpose, ScriptSetupExposeExact);
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-test-workspace/vue-tsc/defineProp_B/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare const ScriptSetupGenericExact: <T, >(
emit: any,
expose(_exposed: {}): void,
}
) => any;
) => import('vue').VNode & { __props?: typeof _props, __ctx?: typeof _ctx };
exactType(ScriptSetup, ScriptSetupExact);
exactType(ScriptSetupGeneric, ScriptSetupGenericExact);
Expand Down

0 comments on commit 184cce1

Please sign in to comment.