type FixedSizeArray = T extends 0 ? void[] : ReadonlyArray & { 0: U; length: T; }; type Measure = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never; type Append = { 0: [U]; 1: [T[0], U]; 2: [T[0], T[1], U]; 3: [T[0], T[1], T[2], U]; 4: [T[0], T[1], T[2], T[3], U]; 5: [T[0], T[1], T[2], T[3], T[4], U]; 6: [T[0], T[1], T[2], T[3], T[4], T[5], U]; 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U]; 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U]; }[Measure]; type AsArray = T extends any[] ? T : [T]; declare class UnsetAdditionalOptions { _UnsetAdditionalOptions: true } type IfSet = X extends UnsetAdditionalOptions ? {} : X; type Callback = (error: E | null, result?: T) => void; type InnerCallback = (error?: E | null | false, result?: T) => void; type FullTap = Tap & { type: "sync" | "async" | "promise", fn: Function } type Tap = TapOptions & { name: string; }; type TapOptions = { before?: string; stage?: number; }; interface HookInterceptor { name?: string; tap?: (tap: FullTap & IfSet) => void; call?: (...args: any[]) => void; loop?: (...args: any[]) => void; error?: (err: Error) => void; result?: (result: R) => void; done?: () => void; register?: (tap: FullTap & IfSet) => FullTap & IfSet; } type ArgumentNames = FixedSizeArray; declare class Hook { constructor(args?: ArgumentNames>, name?: string); name: string | undefined; intercept(interceptor: HookInterceptor): void; isUsed(): boolean; callAsync(...args: Append, Callback>): void; promise(...args: AsArray): Promise; tap(options: string | Tap & IfSet, fn: (...args: AsArray) => R): void; withOptions(options: TapOptions & IfSet): Hook; } export class SyncHook extends Hook { call(...args: AsArray): R; } export class SyncBailHook extends SyncHook {} export class SyncLoopHook extends SyncHook {} export class SyncWaterfallHook extends SyncHook[0], AdditionalOptions> {} declare class AsyncHook extends Hook { tapAsync( options: string | Tap & IfSet, fn: (...args: Append, InnerCallback>) => void ): void; tapPromise( options: string | Tap & IfSet, fn: (...args: AsArray) => Promise ): void; } export class AsyncParallelHook extends AsyncHook {} export class AsyncParallelBailHook extends AsyncHook {} export class AsyncSeriesHook extends AsyncHook {} export class AsyncSeriesBailHook extends AsyncHook {} export class AsyncSeriesLoopHook extends AsyncHook {} export class AsyncSeriesWaterfallHook extends AsyncHook[0], AdditionalOptions> {} type HookFactory = (key: any, hook?: H) => H; interface HookMapInterceptor { factory?: HookFactory; } export class HookMap { constructor(factory: HookFactory, name?: string); name: string | undefined; get(key: any): H | undefined; for(key: any): H; intercept(interceptor: HookMapInterceptor): void; } export class MultiHook { constructor(hooks: H[], name?: string); name: string | undefined; tap(options: string | Tap, fn?: Function): void; tapAsync(options: string | Tap, fn?: Function): void; tapPromise(options: string | Tap, fn?: Function): void; }