an interface in custom.d.ts file:
export interface Request {
user: {
id: string
}
}
but when I import it:
import { Request } from '../types/custom';
router.get('/', auth, async (req: Request, res: Response) => {
I get: Argument of type '(req: Request, res: Response) => Promise<void>' is not assignable to parameter of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs>'.
any idea?
Here you're trying to override Express Request types entirely it seems, your argument types in the handler need to match express request types as well, so I would probably try extending it
interface UserRequest extends express.Request { user: { id: string } }
Is it a business oriented decision that led to this? If it's not, I would advise against this as it couples you to Express forever. You could utilize the app.local as it's defined for that purpose.
Обсуждают сегодня