Skip to content

Commit

Permalink
refactor: add custom context at AllMiddlewareArgs instead of Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
szydlovski committed Oct 13, 2021
1 parent 7170889 commit a799388
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/types/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ export type AnyMiddlewareArgs =
| SlackViewMiddlewareArgs
| SlackShortcutMiddlewareArgs;

export interface AllMiddlewareArgs {
context: Context;
export interface AllMiddlewareArgs<CustomContext = StringIndexed> {
context: Context & CustomContext;
logger: Logger;
client: WebClient;
next: NextFn;
}

export interface ExtendContext<T extends StringIndexed = StringIndexed> { context: T }

// NOTE: Args should extend AnyMiddlewareArgs, but because of contravariance for function types, including that as a
// constraint would mess up the interface of App#event(), App#message(), etc.
export interface Middleware<Args, CustomContext = StringIndexed> {
(args: Args & AllMiddlewareArgs & ExtendContext<CustomContext>): Promise<void>;
(args: Args & AllMiddlewareArgs<CustomContext>): Promise<void>;
}

/**
Expand Down

0 comments on commit a799388

Please sign in to comment.