]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): correct type inference for PascalCase emits (#11579)
author山吹色御守 <85992002+KazariEX@users.noreply.github.com>
Thu, 15 Aug 2024 09:49:43 +0000 (17:49 +0800)
committerGitHub <noreply@github.com>
Thu, 15 Aug 2024 09:49:43 +0000 (17:49 +0800)
fix vuejs/language-tools#4269

packages-private/dts-test/defineComponent.test-d.tsx
packages/runtime-core/src/componentEmits.ts

index 810310bac84d5478545745e878f92f2d7aa44952..79ce6d6956dffd5cb62671b1aaeda28c1a4bdddd 100644 (file)
@@ -906,12 +906,15 @@ describe('emits', () => {
     emits: {
       click: (n: number) => typeof n === 'number',
       input: (b: string) => b.length > 1,
+      Focus: (f: boolean) => !!f,
     },
     setup(props, { emit }) {
       expectType<((n: number) => boolean) | undefined>(props.onClick)
       expectType<((b: string) => boolean) | undefined>(props.onInput)
+      expectType<((f: boolean) => boolean) | undefined>(props.onFocus)
       emit('click', 1)
       emit('input', 'foo')
+      emit('Focus', true)
       //  @ts-expect-error
       emit('nope')
       //  @ts-expect-error
@@ -922,6 +925,10 @@ describe('emits', () => {
       emit('input')
       //  @ts-expect-error
       emit('input', 1)
+      //  @ts-expect-error
+      emit('focus')
+      //  @ts-expect-error
+      emit('focus', true)
     },
     created() {
       this.$emit('click', 1)
@@ -936,6 +943,10 @@ describe('emits', () => {
       this.$emit('input')
       //  @ts-expect-error
       this.$emit('input', 1)
+      //  @ts-expect-error
+      this.$emit('focus')
+      //  @ts-expect-error
+      this.$emit('focus', true)
     },
     mounted() {
       // #3599
@@ -954,6 +965,10 @@ describe('emits', () => {
         this.$emit('input')
         //  @ts-expect-error
         this.$emit('input', 1)
+        //  @ts-expect-error
+        this.$emit('focus')
+        //  @ts-expect-error
+        this.$emit('focus', true)
       })
     },
   })
index 4c3912e0598b49cb69d6915700086aa6ff05203a..dddb2e9453e34b80672401bfba6d9d8f84d65c8f 100644 (file)
@@ -47,15 +47,13 @@ export type EmitsToProps<T extends EmitsOptions | ComponentTypeEmits> =
       }
     : T extends ObjectEmitsOptions
       ? {
-          [K in `on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}`
-            ? (
-                ...args: T[Uncapitalize<C>] extends (...args: infer P) => any
-                  ? P
-                  : T[Uncapitalize<C>] extends null
-                    ? any[]
-                    : never
-              ) => any
-            : never
+          [K in string & keyof T as `on${Capitalize<K>}`]?: (
+            ...args: T[K] extends (...args: infer P) => any
+              ? P
+              : T[K] extends null
+                ? any[]
+                : never
+          ) => any
         }
       : {}