]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): fix using tuple type as EmitsOptions (#2160)
authorwonderful-panda <iwata0303@gmail.com>
Tue, 22 Sep 2020 14:05:37 +0000 (23:05 +0900)
committerGitHub <noreply@github.com>
Tue, 22 Sep 2020 14:05:37 +0000 (10:05 -0400)
fix #2159

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

index 6418f8c7d5d6ba8508560cc5f1071a4dd604f8fd..daf82b71e301a2702141e71cb025bbda0153f0db 100644 (file)
@@ -28,8 +28,8 @@ export type EmitsOptions = ObjectEmitsOptions | string[]
 export type EmitFn<
   Options = ObjectEmitsOptions,
   Event extends keyof Options = keyof Options
-> = Options extends any[]
-  ? (event: Options[0], ...args: any[]) => void
+> = Options extends Array<infer V>
+  ? (event: V, ...args: any[]) => void
   : {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function
     ? (event: string, ...args: any[]) => void
     : UnionToIntersection<
index c53c4287a6e4046636882cb01be8bad88c669f7b..4fe4db645afd77f4cadda7055f28be50748d0deb 100644 (file)
@@ -63,3 +63,12 @@ const Baz: FunctionalComponent<{}, string[]> = (props, { emit }) => {
 }
 
 expectType<Component>(Baz)
+
+const Qux: FunctionalComponent<{}, ['foo', 'bar']> = (props, { emit }) => {
+  emit('foo')
+  emit('foo', 1, 2)
+  emit('bar')
+  emit('bar', 1, 2)
+}
+
+expectType<Component>(Qux)