• Defines a middleware function with type inference.

    A convenience helper that ensures the provided handler conforms to the MiddlewareFn signature while preserving exact parameter and return types. This allows TypeScript to infer narrower types for TParameters and TReturn without needing explicit generic annotations on the handler.

    Use this when defining middleware functions to get accurate type checking and IntelliSense without sacrificing type safety.

    Type Parameters

    • TParameters extends unknown[] = unknown[]

      Type of arguments passed through the middleware chain

    • TReturn = unknown

      Type of value returned from the function

    Parameters

    Returns MiddlewareFn<TParameters, TReturn>

    The same handler, typed as MiddlewareFn.

    const loggingMiddleware = defineMiddleware(({ args, next, context }) => {
    console.log('Before:', args);
    const result = next(args);
    console.log('After:', result);
    return result;
    });

    IMPORT_PATH: @daiso-tech/core/middleware