Definitelytyped: @types/express - Property 'user' does not exist on type 'Request'

Created on 16 Dec 2017  路  6Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/express package and had problems.
  • [ ] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [ ] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [ ] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @borisyankov @19majkel94 @kacepe

Typescript version: 2.6.1
express: 4.16.2
types/express: 4.0.39

When trying:

function(req: Request, res: Response, next: Next) {
  console.log(req.user);
} 

Most helpful comment

@sandcake you try to access req.user, I guess you are using express with passport? If so, you should install @types/passport too.

All 6 comments

Because it doesn't exist in express request object. What is the problem here?

@sandcake you try to access req.user, I guess you are using express with passport? If so, you should install @types/passport too.

@19majkel94 that's confusing because the user field is shown in the autocompletion (using vscode 1.18.1).
Furthermore the error just started popping for a few days after being silent for almost a year.

I don't get it - typescript complain that the property user doesn't exist but typescript provide autocompletion for it? Looks like VSCode bug, not @types/express 馃槈

I think you are right @19majkel94 , i just checked today after a fresh restart and fresh install and can't reproduce it anymore.
I shall then close this issue.

@micksatana that's right, i am using express with passport. Thanks for the tip :) . I shall try it when the error occurs again.

Was this page helpful?
0 / 5 - 0 ratings