title: Typescript - "Authorization" does not exist on type HeadersInit
body: <p>I'm using the <code>node-fetch</code> npm module and have a helper function for making authorized requests to a third party service (basically just middleware for adding in the Authorization header).</p>
  <pre class="lang-js prettyprint-override"><code>async function makeAuthorizedRequest(url: string, options: RequestInit) {
    if (!options) {
      options = { headers: {} as HeadersInit }
    }
    if (!options.headers) {
      options.headers = {} as HeadersInit
    }
    options.headers.Authorization = `Bearer ${access_token}`
    if (!options.headers['User-Agent']) {
      options.headers['User-Agent'] = USERAGENT
    }
    return fetch(url, options)
  }
  </code></pre>
  <p>The <code>RequestInit</code> type is defined as having a <code>headers</code> property of type <code>HeadersInit</code> defined as the following</p>
  <pre class="lang-js prettyprint-override"><code>export type HeadersInit = Headers | string[][] | { [key: string]: string };
  </code></pre>
  <p>I get two distinct errors in my IDE (VSCode) and <code>tsc</code> refuses to compile this because</p>
  <pre><code>Property 'Authorization' does not exist on type 'Headers'.ts(2339)
  </code></pre>
  <p>and</p>
  <pre><code>Element implicitly has an 'any' type because expression of type '&quot;User-Agent&quot;' can't be used to index type 'HeadersInit'.
    Property 'User-Agent' does not exist on type 'HeadersInit'.ts(7053)
  
  </code></pre>
  <p>Now obviously &quot;User-Agent&quot; and &quot;Authorization&quot; are valid http headers, and from my understanding the type <code>{[key: string]: string}</code> definition should allow for this since &quot;User-Agent&quot; and &quot;Authorization&quot; are strings and their values are being set as strings. Why is tsc not able to see this and how can I actually fix it?</p>
  <p>(I've used <code>//@ts-ignore</code> on the affected lines in the past, but I'd like to understand what its concerned about and how to fix this in the future - because having ts-ignore all over the codebase does not look professional)</p>