]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): EmitsOptions support named tuple syntax edison/fix/12673 12676/head
authordaiwei <daiwei521@126.com>
Thu, 9 Jan 2025 08:02:10 +0000 (16:02 +0800)
committerdaiwei <daiwei521@126.com>
Thu, 9 Jan 2025 08:02:10 +0000 (16:02 +0800)
packages-private/dts-test/defineComponent.test-d.tsx
packages/runtime-core/src/componentEmits.ts

index fda3ca4856c746fd0829458bdea4b0f0ae1b675d..3ff27f2fea66d01c8d47dee22ab12f90121e4584 100644 (file)
@@ -1368,6 +1368,20 @@ describe('function syntax w/ emits', () => {
       },
     },
   )
+
+  defineComponent<
+    {},
+    {
+      update: [value: string] // named tuple syntax
+    }
+  >((props, ctx) => {
+    ctx.emit('update', '123')
+    // @ts-expect-error
+    ctx.emit('update', 123)
+    // @ts-expect-error
+    ctx.emit('non-exist')
+    return () => {}
+  })
 })
 
 describe('function syntax w/ runtime props', () => {
index db52bc88c333e02176c4da3409ea89177879250d..86230f874b4187a84586b4176274e6faf201f8fa 100644 (file)
@@ -35,7 +35,7 @@ import type { ComponentPublicInstance } from './componentPublicInstance'
 
 export type ObjectEmitsOptions = Record<
   string,
-  ((...args: any[]) => any) | null
+  ((...args: any[]) => any) | null | any[]
 >
 
 export type EmitsOptions = ObjectEmitsOptions | string[]