diff --git a/src/event-handler/index.ts b/src/event-handler/index.ts index 10d6e7ab..f17bedd7 100644 --- a/src/event-handler/index.ts +++ b/src/event-handler/index.ts @@ -20,7 +20,13 @@ interface EventHandler { event: E | E[], callback: HandlerFunction, ): void; - onAny(handler: (event: EmitterWebhookEvent & TTransformed) => any): void; + onAny( + handler: ( + event: TTransformed extends unknown + ? EmitterWebhookEvent + : EmitterWebhookEvent & TTransformed, + ) => any, + ): void; onError( handler: (event: WebhookEventHandlerError) => any, ): void; diff --git a/src/event-handler/on.ts b/src/event-handler/on.ts index 7d377200..f5c4e400 100644 --- a/src/event-handler/on.ts +++ b/src/event-handler/on.ts @@ -51,7 +51,11 @@ export function receiverOn( export function receiverOnAny( state: State, - handler: (event: EmitterWebhookEvent & TTransformed) => any, + handler: ( + event: TTransformed extends unknown + ? EmitterWebhookEvent + : EmitterWebhookEvent & TTransformed, + ) => any, ) { handleEventHandlers(state, "*", handler); } diff --git a/src/index.ts b/src/index.ts index 2d12e6f1..5dc8d91b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,11 @@ class Webhooks { callback: HandlerFunction, ) => void; public onAny: ( - callback: (event: EmitterWebhookEvent & TTransformed) => any, + callback: ( + event: TTransformed extends unknown + ? EmitterWebhookEvent + : EmitterWebhookEvent & TTransformed, + ) => any, ) => void; public onError: ( callback: (event: WebhookEventHandlerError) => any, diff --git a/src/types.ts b/src/types.ts index d898ad12..e64b07ea 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,7 +64,9 @@ export type WebhookError = Error & Partial; // todo: rename to "EmitterErrorEvent" export interface WebhookEventHandlerError extends AggregateError { - event: EmitterWebhookEvent & TTransformed; + event: TTransformed extends unknown + ? EmitterWebhookEvent + : EmitterWebhookEvent & TTransformed; } /**