Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware type definition misses DecoratorTarget #1695

Open
2 of 4 tasks
savarex opened this issue Jan 8, 2025 · 0 comments
Open
2 of 4 tasks

Middleware type definition misses DecoratorTarget #1695

savarex opened this issue Jan 8, 2025 · 0 comments

Comments

@savarex
Copy link

savarex commented Jan 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hi,
I've updated library inversify-express-utils from 6.3.2 to 6.4.10 and I got this build error

Argument of type 'typeof HttpMyBeautifulMiddleware' is not assignable to parameter of type 'Middleware'.

This happens because Middleware definition changed from (v. 6.3.2)
export type Middleware = (inversifyInterfaces.ServiceIdentifier<any> | express.RequestHandler);
to (v. 6.4.10)
export type Middleware = (string | symbol | RequestHandler

The new definition is too small to allow all ServiceIdentifier available in Inversify as you can use a prototype or a contructor function as decorator target.

Steps to reproduce

  1. Create an empty inversify express project
  2. Create a class HttpMyBeautifulMiddleware that extends from BaseMiddleware
  3. Register class HttpMyBeautifulMiddleware with .toSelf() method
  4. Create a controller using HttpMyBeautifulMiddleware as middleware with its type definition.
    For example @controller('/api/welcome', HttpMyBeautifulMiddleware)

Expected behavior

Build must complete successfully

Possible solution

I suggest to add DecoratorTarget to Middleware definition as you can see below
export type Middleware = (string | symbol | RequestHandler | DecoratorTarget<{ handler: RequestHandler }>

This is enough to make build and running complete successfully keeping middleware type checking.

Package version

6.2.1

Node.js version

20.17

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Stack trace

No response

Other

No response

@savarex savarex changed the title [inversify-espress-utils] Align Middleware type definition to be better compatibile with ServiceIdentifier Middleware type definition miss DecoratorTarget Jan 8, 2025
@savarex savarex changed the title Middleware type definition miss DecoratorTarget Middleware type definition misses DecoratorTarget Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant