title: TypeScript add custom Request header in Express
body: <p>I am trying to add a <strong>custom header</strong> to my request, but it must be modified/implemented in the interface. </p>
  
  <p>The default <code>Request</code> interface references <code>IncomingHttpHeaders</code>. So I am attempting to extend this interface with my own custom token header. </p>
  
  <pre><code>import { IncomingHttpHeaders } from 'http';
  
  declare module 'express-serve-static-core' {
      interface IncomingHttpHeaders {
          "XYZ-Token"?: string
      }
  }
  </code></pre>
  
  <p>I have updated my <code>.tsconfig</code> file to read the <code>./types</code> folder. The name of my file is <code>index.d.ts</code></p>
  
  <p>I can successfully compile the code if I do not use my custom header, but when I try to reference the token header in the code I get the following compilation error: </p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>error TS2538: Type 'string[]' cannot be used as an index type.
  
      req.headers['XYZ-Token']
  
  </code></pre>
  
  <p>If I use any of the values of the original interface everything works fine.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>    req.headers['user-agent']
  </code></pre>
  
  <p><strong>Additional information</strong>: I am using NestJS, which uses Fastify/Express under the hood. I can confirm that the Request interface being used is from Express. Fastify is backwards compatible with all Express modules. Mainly using Fastify because it's faster.</p>