solved it by adding a helper function to create middleware
type InferInput<TProcess> = TProcess extends (ctx: Context<infer I, any>) => any
? I
: never
type InferOutput<TProcess> = TProcess extends (
ctx: Context<any, any>,
) => infer O
? O
: never
export function defineMiddleware<
TProcess extends (ctx: any) => any,
TEvents extends Record<string, (...args: any[]) => void> = {},
>(mw: {
name: string
deps?: (keyof InferInput<TProcess> & string)[]
provides: keyof InferOutput<TProcess> & string
process: TProcess
rollback?: (
ctx: Context<InferInput<TProcess> & InferOutput<TProcess>, TEvents>,
) => void | Promise<void>
}): MiddleWare<InferInput<TProcess>, InferOutput<TProcess>, TEvents> {
return mw as MiddleWare<
InferInput<TProcess>,
InferOutput<TProcess>,
TEvents
>
}