79509483

Date: 2025-03-14 15:18:23
Score: 0.5
Natty:
Report link

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
    >
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: weuoimi