Change Next err paramter to type any
Fixes: #24
I found that the type conflict comes from the err parameter type.
@types/express: (err?: any): void
compose-middleware: (err?: Error | null): void
This PR changes the Next err parameter type to any which matches @types/express.
Reproduction: https://github.com/thomasraydeniscool/compose-middleware-repro
I would have expected err | null to be assignable to any so this is odd. Can you add a test at all?
I'm a little hesitant to land this since it makes the library strictly worse for type safety.
For example, for this to be typed correctly we'd need to change this to any: https://github.com/blakeembrey/compose-middleware/blob/c01e0de6657148540f341c7473562a8400c46f5a/src/index.ts#L13
I took a look at your example and it's actually the bearer library that's incorrect here, not compose-middleware. The type signature says it may pass router to next(), but this library doesn't understand the magic strings that Express.js supports.
It's caused by this line in Express.js:
(deferToNext: "router"): void;
This sounds like things work as expected, this library doesn't support deferToNext and therefore the types are working as expected. What's unexpected is probably that people are using the express.Handler definition without realizing this caveat. I'm not comfortable relaxing the typing here to support something that may actually break in production as a result (e.g. if someone actually calls next("router") and it doesn't work).
The library using express.Handler could be updated to define what it actually uses instead, or we can add next("router") support to this library instead.
I have the same issue. Any plans to get this merged ?
If you’d like to contribute a test case using the types I can look at it.