I have an anonymous function in Express like so:
app.use((err, req, res, next) => {
// ...
});
and I want to set the type of the function to ErrorRequestHandler (Not the return type!).
I can do it like this:
const X: ErrorRequestHandler = (err, req, res, next) => {
// ...
}
app.use(X);
But is there a syntax to do it inline? Like this:
app.use((err, req, res, next) => {
// ...
} : ErrorRequestHandler); // Note: this doesn't work.
app.usehas overlaps with parameter count here, so Typescript can't determine which one you want from parameter count only.app.get('/', (req, res) => {})work fine though.