Skip to content

Commit

Permalink
fix(types): fix using tuple type as EmitsOptions (#2160)
Browse files Browse the repository at this point in the history
fix #2159
  • Loading branch information
wonderful-panda committed Sep 22, 2020
1 parent 6aa2256 commit 5dbd6b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
9 changes: 9 additions & 0 deletions test-dts/functionalComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5dbd6b3

Please sign in to comment.