Skip to content

Commit

Permalink
fix: cannot assign generic component to defineComponent components op…
Browse files Browse the repository at this point in the history
…tion

#2758
  • Loading branch information
johnsoncodehk committed May 1, 2023
1 parent 44357b1 commit 839036d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/vue-language-core/src/generators/script.ts
Expand Up @@ -156,7 +156,7 @@ export function generate(
);
}
if (usedHelperTypes.ToTemplateSlots) {
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]?: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
}
if (usedHelperTypes.PropsChildren) {
codes.push(`type __VLS_PropsChildren<S> = { [K in keyof (boolean extends (JSX.ElementChildrenAttribute extends never ? true : false) ? never : JSX.ElementChildrenAttribute)]?: S; };\n`);
Expand Down
10 changes: 10 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#2758/app.vue
@@ -0,0 +1,10 @@
<script lang="ts">
import { defineComponent } from 'vue';
import MyComp from './main.vue';
export default defineComponent({
components: {
MyComp,
},
});
</script>
8 changes: 4 additions & 4 deletions packages/vue-test-workspace/vue-tsc/components/main.vue
Expand Up @@ -67,9 +67,9 @@ declare const ScriptSetupGenericExact: <T, >(
_props: NonNullable<typeof _setup>['props'] & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
_ctx?: Pick<NonNullable<typeof _setup>, 'attrs' | 'emit' | 'slots'>,
_setup?: {
props: { foo: T } & { [K in keyof JSX.ElementChildrenAttribute]?: { default(data: T): any } },
props: { foo: T } & { [K in keyof JSX.ElementChildrenAttribute]?: { default?(data: T): any } },
attrs: any,
slots: { default(data: T): any },
slots: { default?(data: T): any },
emit: { (e: 'bar', data: T): void },
expose(_exposed: { baz: T }): void,
}
Expand All @@ -83,7 +83,7 @@ exactType(ScriptSetupGeneric, ScriptSetupGenericExact);
exactType((new ShortDefineSlots()).$slots.foo, {} as ((props: {
id: string;
} | undefined) => any) | undefined);
exactType((new ShortDefineSlots()).$slots.bar, {} as (props: {
exactType((new ShortDefineSlots()).$slots.bar, {} as ((props: {
id: number;
}) => any);
}) => any) | undefined);
</script>

0 comments on commit 839036d

Please sign in to comment.