Просмотр исходного кода

fix(types): EmitsOptions support named tuple syntax

daiwei 1 год назад
Родитель
Сommit
5d549d230d

+ 14 - 0
packages-private/dts-test/defineComponent.test-d.tsx

@@ -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', () => {
 describe('function syntax w/ runtime props', () => {

+ 1 - 1
packages/runtime-core/src/componentEmits.ts

@@ -35,7 +35,7 @@ import type { ComponentPublicInstance } from './componentPublicInstance'
 
 
 export type ObjectEmitsOptions = Record<
 export type ObjectEmitsOptions = Record<
   string,
   string,
-  ((...args: any[]) => any) | null
+  ((...args: any[]) => any) | null | any[]
 >
 >
 
 
 export type EmitsOptions = ObjectEmitsOptions | string[]
 export type EmitsOptions = ObjectEmitsOptions | string[]