UNPKG

5.04 kBTypeScriptView Raw
1declare const assignmentCompatibilityHack: unique symbol;
2export declare type MatchingKeys<TRecord, TMatch, K extends keyof TRecord = keyof TRecord> = K extends (TRecord[K] extends TMatch ? K : never) ? K : never;
3export declare type VoidKeys<Record> = MatchingKeys<Record, void>;
4export interface TypeRecord<T, U, V> {
5 ' _emitterType'?: T;
6 ' _eventsType'?: U;
7 ' _emitType'?: V;
8}
9export declare type ReturnTypeOfMethod<T> = T extends (...args: any[]) => any ? ReturnType<T> : void;
10export declare type ReturnTypeOfMethodIfExists<T, S extends string> = S extends keyof T ? ReturnTypeOfMethod<T[S]> : void;
11export declare type InnerEEMethodReturnType<T, TValue, FValue> = T extends (...args: any[]) => any ? ReturnType<T> extends void | undefined ? FValue : TValue : FValue;
12export declare type EEMethodReturnType<T, S extends string, TValue, FValue = void> = S extends keyof T ? InnerEEMethodReturnType<T[S], TValue, FValue> : FValue;
13declare type ListenerType<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T];
14export declare type OverriddenMethods<TEmitter, TEventRecord, TEmitRecord = TEventRecord> = {
15 on<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'on', T>;
16 on(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
17 addListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'addListener', T>;
18 addListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
19 addEventListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'addEventListener', T>;
20 addEventListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
21 removeListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: any[]) => any): EEMethodReturnType<TEmitter, 'removeListener', T>;
22 removeListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
23 removeEventListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: any[]) => any): EEMethodReturnType<TEmitter, 'removeEventListener', T>;
24 removeEventListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
25 once<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'once', T>;
26 once(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
27 emit<P extends keyof TEmitRecord, T>(this: T, event: P, ...args: ListenerType<TEmitRecord[P]>): EEMethodReturnType<TEmitter, 'emit', T>;
28 emit(event: typeof assignmentCompatibilityHack, ...args: any[]): void;
29};
30export declare type OverriddenKeys = keyof OverriddenMethods<any, any, any>;
31export declare type StrictEventEmitter<TEmitterType, TEventRecord, TEmitRecord = TEventRecord, UnneededMethods extends Exclude<OverriddenKeys, keyof TEmitterType> = Exclude<OverriddenKeys, keyof TEmitterType>, NeededMethods extends Exclude<OverriddenKeys, UnneededMethods> = Exclude<OverriddenKeys, UnneededMethods>> = TypeRecord<TEmitterType, TEventRecord, TEmitRecord> & Pick<TEmitterType, Exclude<keyof TEmitterType, OverriddenKeys>> & Pick<OverriddenMethods<TEmitterType, TEventRecord, TEmitRecord>, NeededMethods>;
32export default StrictEventEmitter;
33export declare type NoUndefined<T> = T extends undefined ? never : T;
34export declare type StrictBroadcast<TEmitter extends TypeRecord<any, any, any>, TEmitRecord extends NoUndefined<TEmitter[' _emitType']> = NoUndefined<TEmitter[' _emitType']>, VK extends VoidKeys<TEmitRecord> = VoidKeys<TEmitRecord>, NVK extends Exclude<keyof TEmitRecord, VK> = Exclude<keyof TEmitRecord, VK>> = {
35 <E extends NVK>(event: E, request: TEmitRecord[E]): any;
36 <E extends VK>(event: E): any;
37};
38export declare type EventNames<TEmitter extends TypeRecord<any, any, any>, TEventRecord extends NoUndefined<TEmitter[' _eventsType']> = NoUndefined<TEmitter[' _eventsType']>, TEmitRecord extends NoUndefined<TEmitter[' _emitType']> = NoUndefined<TEmitter[' _emitType']>> = keyof TEmitRecord | keyof TEventRecord;
39export declare type OnEventNames<TEmitter extends TypeRecord<any, any, any>, TEventRecord extends NoUndefined<TEmitter[' _eventsType']> = NoUndefined<TEmitter[' _eventsType']>, TEmitRecord extends NoUndefined<TEmitter[' _emitType']> = NoUndefined<TEmitter[' _emitType']>> = keyof TEventRecord;
40export declare type EmitEventNames<TEmitter extends TypeRecord<any, any, any>, TEventRecord extends NoUndefined<TEmitter[' _eventsType']> = NoUndefined<TEmitter[' _eventsType']>, TEmitRecord extends NoUndefined<TEmitter[' _emitType']> = NoUndefined<TEmitter[' _emitType']>> = keyof TEmitRecord;
41
\No newline at end of file