element-plus/packages/utils/types.ts

23 lines
790 B
TypeScript
Raw Normal View History

import type { App } from 'vue'
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
2020-09-03 21:19:12 +08:00
export type PartialReturnType<T extends (...args: unknown[]) => unknown> = Partial<ReturnType<T>>
export type SFCWithInstall<T> = T & { install(app: App): void; }