Browse Source

fix(types): defineEmits w/ interface declaration (#12343)

close #8457
edison 1 year ago
parent
commit
1022eabaa1

+ 8 - 0
packages-private/dts-test/setupHelpers.test-d.ts

@@ -306,6 +306,14 @@ describe('defineEmits w/ type declaration', () => {
   emit2('baz')
 })
 
+describe('defineEmits w/ interface declaration', () => {
+  interface Emits {
+    foo: [value: string]
+  }
+  const emit = defineEmits<Emits>()
+  emit('foo', 'hi')
+})
+
 describe('defineEmits w/ alt type declaration', () => {
   const emit = defineEmits<{
     foo: [id: string]

+ 1 - 3
packages/runtime-core/src/apiSetupHelpers.ts

@@ -149,9 +149,7 @@ export function defineEmits() {
   return null as any
 }
 
-export type ComponentTypeEmits =
-  | ((...args: any[]) => any)
-  | Record<string, any[]>
+export type ComponentTypeEmits = ((...args: any[]) => any) | Record<string, any>
 
 type RecordToUnion<T extends Record<string, any>> = T[keyof T]