title: TypeScript + Express + Passport.js - Property id does not exist on type User
body: <p>I'm new to TypeScript, I implemented user authentication using Passport.js in a small app I'm making just for practice.</p>
  <p><strong>Problem</strong></p>
  <p>I'm trying to tell Passport.js to save the user property <code>id</code> into the session for further authentication, but I just can't find a way to tell TypeScript that the property <code>id</code> of <code>user</code> actually exists.</p>
  <pre><code>passport.serializeUser((user, done) =&gt; {
    done(undefined, user.id); // Property 'id' does not exists on type 'User' 
  });
  </code></pre>
  <p>The parameter <code>user</code> shows off as type <code>Express.User</code>, but it actually is an instance of a TypeOrm entity <code>User</code>. Searching through posts I found out I can extend the type <code>Express.User</code> to add the property that I need to use:</p>
  <pre><code>  // src/custom-typings/index.d.ts
    namespace Express {
      interface User {
        id?: number;
      }
    }
  </code></pre>
  <p>Doing this removes the error warning when coding, but when I try to compile the code, the error shows up again, but in my VSCode terminal!.</p>
  <pre><code>src/core/passport.ts:38:24 - error TS2339: Property 'id' does not exist on type 'User'.
  
  38   done(undefined, user.id);
                            ~~
  
      at createTSError (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:513:12)
      at reportTSError (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:517:19)
      at getOutput (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:752:36)
      at Object.compile (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:968:32)
      at Module.m._compile (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:1056:42)
      at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
      at Object.require.extensions.&lt;computed&gt; [as .ts] (C:\Users\fvg\Desktop\Proyectos\passport-local-example\node_modules\ts-node\src\index.ts:1059:12)
      at Module.load (internal/modules/cjs/loader.js:985:32)
      at Function.Module._load (internal/modules/cjs/loader.js:878:14)
      at Module.require (internal/modules/cjs/loader.js:1025:19)
  </code></pre>
  <p>I did add my custom typings into my tsconfig.json:</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;es5&quot;,                       
      &quot;module&quot;: &quot;commonjs&quot;,                   
      &quot;lib&quot;: [&quot;es6&quot;],
      &quot;outDir&quot;: &quot;dist&quot;,                   
      &quot;rootDir&quot;: &quot;src&quot;,                         
      &quot;strict&quot;: true,                  
      &quot;typeRoots&quot;: [&quot;./src/custom-typings&quot;, &quot;./node_modules/@types&quot;],                     
      &quot;esModuleInterop&quot;: true,
      &quot;experimentalDecorators&quot;: true,     
      &quot;emitDecoratorMetadata&quot;: true,       
      &quot;resolveJsonModule&quot;: true,        
      &quot;skipLibCheck&quot;: true,              
      &quot;forceConsistentCasingInFileNames&quot;: true
    }
  }
  </code></pre>
  <p>This is my project structure:</p>
  <pre><code>.
  ├── src
  │   ├── core
  │   │     └── passport.ts
  │   │  
  │   │
  │   ├── custom-typings
  │   │             └── index.d.ts
  │   │
  │   └── other stuff
  │ 
  │
  ├── tsconfig.json
  </code></pre>
  <p>All other solutions say that this is to way to fix this typical problem, but I just can't make it work, what am I missing?.</p>