types(runtime-core): provide valid type for default $emit (#1498)

This commit is contained in:
Carlos Rodrigues
2020-07-08 16:51:03 +01:00
committed by GitHub
parent f0394e2a61
commit 1e90605c15
4 changed files with 28 additions and 11 deletions

View File

@@ -25,13 +25,15 @@ export type EmitFn<
Event extends keyof Options = keyof Options
> = Options extends any[]
? (event: Options[0], ...args: any[]) => void
: UnionToIntersection<
{
[key in Event]: Options[key] extends ((...args: infer Args) => any)
? (event: key, ...args: Args) => void
: (event: key, ...args: any[]) => void
}[Event]
>
: {} 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<
{
[key in Event]: Options[key] extends ((...args: infer Args) => any)
? (event: key, ...args: Args) => void
: (event: key, ...args: any[]) => void
}[Event]
>
export function emit(
instance: ComponentInternalInstance,