UNPKG

642 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 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
13) => Promise<unknown> | void
14
15export interface MiddlewareObj<C extends Context> {
16 middleware: () => MiddlewareFn<C>
17}
18
19export type Middleware<C extends Context> = MiddlewareFn<C> | MiddlewareObj<C>