Skip to content

Commit b92f46b

Browse files
authored
fix(vue-component-type-helpers): correctly handle generic components when using ComponentExposed (#3536)
1 parent cc78c5f commit b92f46b

File tree

4 files changed

+4
-1
lines changed

4 files changed

+4
-1
lines changed

packages/vue-component-type-helpers/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type ComponentEmit<T> =
2424

2525
export type ComponentExposed<T> =
2626
T extends new () => infer E ? E :
27-
T extends (props: any, ctx: { expose(exposed: infer E): any; }, ...args: any) => any ? NonNullable<E> :
27+
T extends (props: any, ctx: any, expose: (exposed: infer E) => any, ...args: any) => any ? NonNullable<E> :
2828
{};
2929

3030
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export function generate(
317317
`& import('${vueCompilerOptions.lib}').ComponentCustomProps,\n`,
318318
);
319319
codes.push(`__VLS_ctx?: Pick<Awaited<typeof __VLS_setup>, 'attrs' | 'emit' | 'slots'>,\n`);
320+
codes.push(`__VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],\n`);
320321
codes.push('__VLS_setup = (async () => {\n');
321322
scriptSetupGeneratedOffset = generateSetupFunction(true, 'none', definePropMirrors);
322323

packages/vue-test-workspace/vue-tsc/non-strict-template/components/main.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const ScriptSetupDefaultPropsExact = defineComponent({
6565
declare const ScriptSetupGenericExact: <T, >(
6666
_props: NonNullable<Awaited<typeof _setup>>['props'] & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
6767
_ctx?: Pick<NonNullable<Awaited<typeof _setup>>, 'attrs' | 'emit' | 'slots'>,
68+
_expose?: NonNullable<Awaited<typeof _setup>>['expose'],
6869
_setup?: Promise<{
6970
props: { foo: T } & { [K in keyof JSX.ElementChildrenAttribute]?: { default?(data: T): any } },
7071
attrs: any,

packages/vue-test-workspace/vue-tsc/non-strict-template/defineProp_B/main.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const ScriptSetupExact = defineComponent({
2121
declare const ScriptSetupGenericExact: <T, >(
2222
_props: NonNullable<Awaited<typeof _setup>>['props'] & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
2323
_ctx?: Pick<NonNullable<Awaited<typeof _setup>>, 'attrs' | 'emit' | 'slots'>,
24+
_expose?: NonNullable<Awaited<typeof _setup>>['expose'],
2425
_setup?: Promise<{
2526
props: {
2627
a?: T | undefined;

0 commit comments

Comments
 (0)