2020-08-04 10:49:49 +08:00
|
|
|
type OptionalKeys<T extends Record<string, unknown>> = {
|
2020-08-02 18:27:46 +08:00
|
|
|
[K in keyof T]: T extends Record<K, T[K]>
|
|
|
|
? never
|
|
|
|
: K
|
|
|
|
}[keyof T]
|
|
|
|
|
2020-08-04 10:49:49 +08:00
|
|
|
type RequiredKeys<T extends Record<string, unknown>> = Exclude<keyof T, OptionalKeys<T>>
|
2020-08-02 18:27:46 +08:00
|
|
|
|
|
|
|
type MonoArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg?: T[K]) => void
|
|
|
|
|
|
|
|
type BiArgEmitter<T, Keys extends keyof T> = <K extends Keys>(evt: K, arg: T[K]) => void
|
|
|
|
|
2020-08-04 10:49:49 +08:00
|
|
|
export type EventEmitter<T extends Record<string, unknown>> =
|
2020-08-02 18:27:46 +08:00
|
|
|
MonoArgEmitter<T, OptionalKeys<T>> & BiArgEmitter<T, RequiredKeys<T>>
|
2020-08-24 15:38:30 +08:00
|
|
|
|
|
|
|
export type AnyFunction<T> = (...args: any[]) => T
|