Middleware object type inference
-
I'm submitting a ... [x] feature request
-
Summary This handler is well designed and I am using it in more than 3 projects. Using TS, I am trying to infer the type of
middlewarewithout success;
const router = new RouterBuilder();
router.use(() => ...).get(req => req.middleware );
Is there a way that it can be handled?
If not, I would suggest to add the ability of adding use in the builder constructor.
That way the entire router can have access to the return type of each use middleware:
const router = new RouterBuilder({ use: [() => ...] });
Currently I am handling it with (not so friendly when you have many routes and middlewares) hacks like this:
const abcMiddleware = async () => ({ abc: true });
type ABC = Awaited<ReturnType<typeof abcMiddleware>>;
router.use(abcMiddleware).get<{}, ABC>(
async ( req, res ) => ({
abc: req.middleware.abc,
})
);
hmm this is a good feature that we should be able to use with use & inject
think its doable with current implementation, let me have a think
@MutabaziAlleluia I tried a few ways to tweak with typescript definition, but still no lucks
Feel free to open a PR?