Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): correct type inference on empty emits with strictTemplates #4700

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>'}`;
const fnEmitType = `K extends { $emit: infer Emit } ? ${strictTemplates ? 'Emit extends (event: infer E, ...args: any[]) => void ? __VLS_IsEqualStrict<E, string> extends true ? {} : Emit : any' : 'Emit'} : any`;
let text = ``;
if (target < 3.5) {
text += `
Expand Down Expand Up @@ -39,6 +40,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
type __VLS_IsEqualStrict<A, B> = A extends B ? B extends A ? true : false : false;
type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
Expand Down Expand Up @@ -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>
: T extends (...args: any) => any ? T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"exclude": [
"../vue3_strictTemplate/#3140",
"../vue3_strictTemplate/#3718",
"../vue3_strictTemplate/emptyEmits",
"../vue3_strictTemplate/intrinsicProps",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<!-- @vue-expect-error -->
<Foo @click="() => {}"></Foo>
</template>

<script setup lang="ts">
import { defineComponent } from 'vue';

const Foo = defineComponent({});
</script>