Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix(types): transform method only accepts current event type #492

Closed
4 changes: 2 additions & 2 deletions src/event-handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { receiverHandle as receive } from "./receive";
import { removeListener } from "./remove-listener";

interface EventHandler<T extends Options> {
interface EventHandler<T extends Options<EmitterWebhookEventName>> {
on<E extends EmitterWebhookEventName>(
event: E | E[],
callback: HandlerFunction<E, T["transform"]>
Expand All @@ -29,7 +29,7 @@ interface EventHandler<T extends Options> {
receive(event: EmitterWebhookEvent): Promise<void>;
}

export function createEventHandler<T extends Options>(
export function createEventHandler<T extends Options<EmitterWebhookEventName>>(
options?: T
): EventHandler<T> {
const state: State = {
Expand Down
7 changes: 5 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ interface BaseWebhookEvent<TName extends WebhookEventName> {
payload: WebhookEventMap[TName];
}

export interface Options<TTransformed = unknown> {
export interface Options<
E extends EmitterWebhookEventName = any,
TTransformed extends EmitterWebhookEvent<E> = any
Comment on lines +25 to +26
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to improve these any default values here. Is it possible?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can default to EmitterWebhookEventName, it's done elsewhere in the code

> {
path?: string;
secret?: string;
transform?: TransformMethod<TTransformed>;
Expand All @@ -43,7 +46,7 @@ type Hooks = {
[key: string]: Function[];
};

export interface State extends Options<any> {
export interface State extends Options {
eventHandler?: any;
hooks: Hooks;
log: Logger;
Expand Down