I have this piece of code in Express TypeScript
import { Router } from "express";
export const skillsRouter = Router()
skillsRouter.use((req, res, next) => {}) // Typescript knows the types of req, res and next
skillsRouter.use((err, req, res, next) => {}) // TypeScript throws implicit any error
skillsRouter.get("/", (req, res) => {
res.status(200).json("ok")
}) // Typescript again knows the types of req and res
Why doesn't it know the types of the Error handler params
Also I'm aware that this will fix it
skillsRouter.use(((err, req, res, next) => {}) as ErrorRequestHandler)
or this
skillsRouter.use((err: unknown, req: Request, res: Response, next: NextFunction) => {})
usejust has the types for handler not for error handler so have to explicitly type it, not ideal but its as it is, you can overwrite types if you want to.