z4nr34l / nemo

Missing polyfill for multiple next.js middlewares
https://nemo.rescale.build
MIT License
156 stars 6 forks source link

Incompatibility Error with Middleware Type Signature #108

Closed gabrielgstein-dev closed 1 week ago

gabrielgstein-dev commented 1 week ago

Hello @rescale team,

First of all, I want to express my appreciation for your solution—it is simple, effective, and very useful for integrating multiple middlewares effortlessly in Next.js projects. Great job!

However, I encountered an issue when trying to use the createMiddleware function as shown in the screenshot below. The error message states that the argument type for my middleware functions does not match the expected type signature. Here is the specific error message I received:

O argumento do tipo '{ '/body': () => (request: NextRequest) => Promise<NextResponse<unknown>>; }' não é atribuível ao parâmetro do tipo 'MiddlewareConfig'.
  A propriedade ''/body'' é incompatível com a assinatura de índice.
    O tipo '() => (request: NextRequest) => Promise<NextResponse<unknown>>' não pode ser atribuído ao tipo 'MiddlewareFunction | MiddlewareFunction[]'.
      O tipo '() => (request: NextRequest) => Promise<NextResponse<unknown>>' não pode ser atribuído ao tipo 'MiddlewareFunction'.
        O tipo '(request: NextRequest) => Promise<NextResponse<unknown>>' não pode ser atribuído ao tipo 'NextResponse<unknown> | Response | Promise<NextResponse<unknown> | Response>'.ts(2345)

English:

Argument of type '{ '/body': (request: NextRequest) => Promise<NextResponse>; }' is not assignable to parameter of type 'MiddlewareFunction | MiddlewareFunction[] | undefined'. The type '(request: NextRequest) => Promise<NextResponse>' is not assignable to type 'MiddlewareFunction'.

image

From the error message, it seems that the middleware type definition is not compatible with the implementation used. Could you please provide guidance on how to correctly define the middleware functions or if there's a potential bug that needs fixing?

Thank you again for your excellent work, and I look forward to your feedback.

Best regards,
Gabriel Stein

linear[bot] commented 1 week ago

NEMO-26 Incompatibility Error with Middleware Type Signature

gabrielgstein-dev commented 1 week ago

Hello @rescale team,

Thank you once again for your prompt response and for the incredible solution provided by your package. I'm happy to inform you that we were able to resolve the issue regarding the middleware type signature mismatch.

The problem was resolved by adjusting the middleware definition to match the expected MiddlewareFunction type, specifically by modifying the middleware to accept MiddlewareFunctionProps as its parameter. This aligned the middleware with the expected type signature required by the createMiddleware function, and the implementation now works seamlessly.

image

Thanks for your support and for creating such a useful and straightforward tool!

Best regards,
Gabriel Stein