diff --git a/packages/language-core/lib/codegen/globalTypes.ts b/packages/language-core/lib/codegen/globalTypes.ts index 2e8f91c23e..f7a46a8aef 100644 --- a/packages/language-core/lib/codegen/globalTypes.ts +++ b/packages/language-core/lib/codegen/globalTypes.ts @@ -2,6 +2,7 @@ import { getSlotsPropertyName } from '../utils/shared'; export function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean) { const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record'}`; + const fnEmitType = `K extends { $emit: infer Emit } ? ${strictTemplates ? 'Emit extends (event: infer E, ...args: any[]) => void ? __VLS_IsEqualStrict extends true ? {} : Emit : any' : 'Emit'} : any`; let text = ``; if (target < 3.5) { text += ` @@ -39,6 +40,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives; type __VLS_IsAny = 0 extends 1 & T ? true : false; type __VLS_PickNotAny = __VLS_IsAny extends true ? B : A; + type __VLS_IsEqualStrict = A extends B ? B extends A ? true : false : false; type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void; type __VLS_WithComponent = N1 extends keyof LocalComponents ? N1 extends N0 ? Pick : { [K in N0]: LocalComponents[N1] } : @@ -128,7 +130,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: { attrs?: any, slots?: K extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : any, - emit?: K extends { $emit: infer Emit } ? Emit : any + emit?: ${fnEmitType} } & { props?: ${fnPropsType}; expose?(exposed: K): void; } } : T extends () => any ? (props: {}, ctx?: any) => ReturnType : T extends (...args: any) => any ? T diff --git a/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json b/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json index 141c51abdd..35e257c8f3 100644 --- a/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json +++ b/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json @@ -11,6 +11,7 @@ "exclude": [ "../vue3_strictTemplate/#3140", "../vue3_strictTemplate/#3718", + "../vue3_strictTemplate/emptyEmits", "../vue3_strictTemplate/intrinsicProps", ] } diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/emptyEmits/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/emptyEmits/main.vue new file mode 100644 index 0000000000..95e3142694 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/emptyEmits/main.vue @@ -0,0 +1,10 @@ + + + \ No newline at end of file