From 6ead0b705ab7263df323f7dc44f14db953e89a9e Mon Sep 17 00:00:00 2001 From: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> Date: Fri, 17 Nov 2023 20:40:04 -0500 Subject: [PATCH] fix: pass through `TTransformed` to `onAny` and `onError` (#924) See https://github.com/probot/probot/issues/1643 --- src/event-handler/index.ts | 10 ++++++---- src/event-handler/on.ts | 8 ++++---- src/index.ts | 8 ++++++-- src/types.ts | 5 +++-- 4 files changed, 19 insertions(+), 12 deletions(-) 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; } /**