Why can't I extend an Express Request Type?

Viewed 35

I have:

import { Request, Response, NextFunction } from 'express';
interface IUserRequest extends Request {
  user: User;
}


  async use(req: IUserRequest, res: Response, next: NextFunction) {
    const apiKey: string = String(req.headers['x-api-key']).trim();

But TypeScript 3.7.4, complains: Property 'headers' does not exist on type 'IUserRequest'.

What am I doing wrong?

1 Answers

Wow - that was silly. Turns out my express was in devDependencies. Once I installed those, it worked flawlessly.

Related