UNPKG

572 BPlain TextView Raw
1import { Context } from './context'
2
3/*
4 next's parameter is in a contravariant position, and thus, trying to type it
5 prevents assigning `MiddlewareFn<ContextMessageUpdate>`
6 to `MiddlewareFn<CustomContext>`.
7 Middleware passing the parameter should be a separate type instead.
8*/
9export type MiddlewareFn<C extends Context> = (
10 ctx: C,
11 next: () => Promise<void>
12) => Promise<unknown> | void
13
14export interface MiddlewareObj<C extends Context> {
15 middleware: () => MiddlewareFn<C>
16}
17
18export type Middleware<C extends Context> = MiddlewareFn<C> | MiddlewareObj<C>