diff --git a/src/event-handler/index.ts b/src/event-handler/index.ts index e86c12cf..ea6bd98d 100644 --- a/src/event-handler/index.ts +++ b/src/event-handler/index.ts @@ -20,8 +20,10 @@ interface EventHandler { event: E | E[], callback: HandlerFunction, ): void; - onAny(handler: (event: EmitterWebhookEvent) => any): void; - onError(handler: (event: WebhookEventHandlerError) => any): void; + onAny(handler: (event: EmitterWebhookEvent & TTransformed) => any): void; + onError( + handler: (event: WebhookEventHandlerError) => any, + ): void; removeListener( event: E | E[], callback: HandlerFunction, @@ -43,8 +45,8 @@ export function createEventHandler( return { on: on.bind(null, state), - onAny: onAny.bind(null, state), - onError: onError.bind(null, state), + onAny: (onAny).bind(null, state), + onError: (onError).bind(null, state), removeListener: removeListener.bind(null, state), receive: receive.bind(null, state), }; diff --git a/src/event-handler/on.ts b/src/event-handler/on.ts index cbec9162..e95e6216 100644 --- a/src/event-handler/on.ts +++ b/src/event-handler/on.ts @@ -49,16 +49,16 @@ export function receiverOn( handleEventHandlers(state, webhookNameOrNames, handler); } -export function receiverOnAny( +export function receiverOnAny( state: State, - handler: (event: EmitterWebhookEvent) => any, + handler: (event: EmitterWebhookEvent & TTransformed) => any, ) { handleEventHandlers(state, "*", handler); } -export function receiverOnError( +export function receiverOnError( state: State, - handler: (event: WebhookEventHandlerError) => any, + handler: (event: WebhookEventHandlerError) => any, ) { handleEventHandlers(state, "error", handler); } diff --git a/src/index.ts b/src/index.ts index d5c3ed6d..373cb2a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,8 +25,12 @@ class Webhooks { event: E | E[], callback: HandlerFunction, ) => void; - public onAny: (callback: (event: EmitterWebhookEvent) => any) => void; - public onError: (callback: (event: WebhookEventHandlerError) => any) => void; + public onAny: ( + callback: (event: EmitterWebhookEvent & TTransformed) => any, + ) => void; + public onError: ( + callback: (event: WebhookEventHandlerError) => any, + ) => void; public removeListener: ( event: E | E[], callback: RemoveHandlerFunction, diff --git a/src/types.ts b/src/types.ts index 1acfe1a9..d3c92ca7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,8 +62,9 @@ export interface State extends Options { export type WebhookError = Error & Partial; // todo: rename to "EmitterErrorEvent" -export interface WebhookEventHandlerError extends AggregateError { - event: EmitterWebhookEvent; +export interface WebhookEventHandlerError + extends AggregateError { + event: EmitterWebhookEvent & TTransformed; } /**