Skip to content

Commit 839036d

Browse files
committed
fix: cannot assign generic component to defineComponent components option
#2758
1 parent 44357b1 commit 839036d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/vue-language-core/src/generators/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function generate(
156156
);
157157
}
158158
if (usedHelperTypes.ToTemplateSlots) {
159-
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
159+
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]?: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
160160
}
161161
if (usedHelperTypes.PropsChildren) {
162162
codes.push(`type __VLS_PropsChildren<S> = { [K in keyof (boolean extends (JSX.ElementChildrenAttribute extends never ? true : false) ? never : JSX.ElementChildrenAttribute)]?: S; };\n`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script lang="ts">
2+
import { defineComponent } from 'vue';
3+
import MyComp from './main.vue';
4+
5+
export default defineComponent({
6+
components: {
7+
MyComp,
8+
},
9+
});
10+
</script>

packages/vue-test-workspace/vue-tsc/components/main.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ declare const ScriptSetupGenericExact: <T, >(
6767
_props: NonNullable<typeof _setup>['props'] & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
6868
_ctx?: Pick<NonNullable<typeof _setup>, 'attrs' | 'emit' | 'slots'>,
6969
_setup?: {
70-
props: { foo: T } & { [K in keyof JSX.ElementChildrenAttribute]?: { default(data: T): any } },
70+
props: { foo: T } & { [K in keyof JSX.ElementChildrenAttribute]?: { default?(data: T): any } },
7171
attrs: any,
72-
slots: { default(data: T): any },
72+
slots: { default?(data: T): any },
7373
emit: { (e: 'bar', data: T): void },
7474
expose(_exposed: { baz: T }): void,
7575
}
@@ -83,7 +83,7 @@ exactType(ScriptSetupGeneric, ScriptSetupGenericExact);
8383
exactType((new ShortDefineSlots()).$slots.foo, {} as ((props: {
8484
id: string;
8585
} | undefined) => any) | undefined);
86-
exactType((new ShortDefineSlots()).$slots.bar, {} as (props: {
86+
exactType((new ShortDefineSlots()).$slots.bar, {} as ((props: {
8787
id: number;
88-
}) => any);
88+
}) => any) | undefined);
8989
</script>

0 commit comments

Comments
 (0)