element-plus/packages/utils/types.ts

17 lines
592 B
TypeScript
Raw Normal View History

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>>
export type AnyFunction<T> = (...args: any[]) => T