advanced-patterns-workshop icon indicating copy to clipboard operation
advanced-patterns-workshop copied to clipboard

Logic issue in 22th problem example

Open bacher opened this issue 2 years ago • 0 comments

I found the logical issue in 22th problem

Middleware type don't consider promises as output.

If we add one more middleware after middleware with async function we see that req become Promise:

image

Solution: add Promise<> variant to return value:

use<NewTOutput extends TOutput>(
    middleware: Middleware<TOutput, NewTOutput | Promise<NewTOutput>>
  ): DynamicMiddleware<TInput, NewTOutput>  {
    this.middleware.push(middleware);
    ...

+ | Promise<NewTOutput> solves the problem

bacher avatar Dec 14 '22 11:12 bacher