From 12afb27555288c5d5fa4044195e014092b75b48e Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sat, 13 Mar 2021 00:06:23 +0100 Subject: [PATCH] fix(types): transform method only accepts current event type --- src/event-handler/index.ts | 8 ++++---- src/index.ts | 4 ++-- src/types.ts | 9 ++------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/event-handler/index.ts b/src/event-handler/index.ts index 754081b3..8d152b0a 100644 --- a/src/event-handler/index.ts +++ b/src/event-handler/index.ts @@ -15,23 +15,23 @@ import { import { receiverHandle as receive } from "./receive"; import { removeListener } from "./remove-listener"; -interface EventHandler { +interface EventHandler { on( event: E | E[], - callback: HandlerFunction + callback: HandlerFunction ): void; onAny(handler: (event: EmitterWebhookEvent) => any): void; onError(handler: (event: WebhookEventHandlerError) => any): void; removeListener( event: E | E[], - callback: HandlerFunction + callback: HandlerFunction ): void; receive(event: EmitterWebhookEvent): Promise; } export function createEventHandler( options?: T -): EventHandler { +): EventHandler { const state: State = { hooks: {}, log: createLogger(options && options.log), diff --git a/src/index.ts b/src/index.ts index 08c2bf00..00d53ff8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,13 +22,13 @@ class Webhooks { public verify: (eventPayload: string | object, signature: string) => boolean; public on: ( event: E | E[], - callback: HandlerFunction + callback: HandlerFunction ) => void; public onAny: (callback: (event: EmitterWebhookEvent) => any) => void; public onError: (callback: (event: WebhookEventHandlerError) => any) => void; public removeListener: ( event: E | E[], - callback: HandlerFunction + callback: HandlerFunction ) => void; public receive: (event: EmitterWebhookEvent) => Promise; public middleware: ( diff --git a/src/types.ts b/src/types.ts index b25b3ff7..fc9970f7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,13 +30,8 @@ export interface Options { type TransformMethod = (event: EmitterWebhookEvent) => T | PromiseLike; -export type HandlerFunction< - TName extends EmitterWebhookEventName, - TTransform -> = ( - event: TTransform extends TransformMethod - ? T - : EmitterWebhookEvent +export type HandlerFunction = ( + event: EmitterWebhookEvent ) => any; type Hooks = {