1 | import { 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 | */
|
9 | export 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 |
|
15 | export interface MiddlewareObj<C extends Context> {
|
16 | middleware: () => MiddlewareFn<C>
|
17 | }
|
18 |
|
19 | export type Middleware<C extends Context> = MiddlewareFn<C> | MiddlewareObj<C>
|