title: How to define Type of dynamically added global variables for Intellisense
body: <p>I am defining four global variables from a forEach loop using a line similar to this:</p>
  <pre><code>global[name] = buffer
  </code></pre>
  <p>with buffer being <a href="https://nodejs.org/api/buffer.html#class-buffer" rel="nofollow noreferrer">the type from node.js</a></p>
  <p>and currently have the very ugly way to get my intellisense for it by having this after the loop:</p>
  <pre><code>// next line only so intellisense works, ALWAYS comment out before running
  const btMapProvinces = Buffer.alloc(1), btMapTerrain = Buffer.alloc(1), btMapRivers = Buffer.alloc(1), btMapHeightmap = Buffer.alloc(1);
  </code></pre>
  <p>Now as i learned about how to use JSDoc to get Intellisense for arguments in modules i was sure i could use that to get Intellisense for my variables instead, but after reading through <a href="https://jsdoc.app/index.html" rel="nofollow noreferrer">the whole documentation</a> i can't seem to get it working.</p>
  <p>My current attempt looks like this:</p>
  <pre><code>/**
   * @var {Buffer} btMapProvinces
   * @var {Buffer} btMapTerrain
   * @var {Buffer} btMapRivers
   * @var {Buffer} btMapHeightmap
   */
  </code></pre>
  <p>but it just doesn't work at all, no matter if it is right before the <code>global[name] = buffer</code> line, at the beginning of the script, or after the forEach...</p>
  <p>I previously also tried using <code>@name</code> like this:</p>
  <pre><code>/**
   * @name btMapProvinces
   * @type {Buffer}
   * @name btMapTerrain
   * @type {Buffer}
   * @name btMapRivers
   * @type {Buffer}
   * @name btMapHeightmap
   * @type {Buffer}
   */
  </code></pre>
  <p>though this did not work aswell</p>
  <p>The last two hours i spent looking through other asks, of which these are the ones i found the most interesting:</p>
  <ul>
  <li>It's a pretty similar situation to this i think, except that i'm not using Typescript: <a href="https://stackoverflow.com/questions/69604913/jsdoc-how-to-specify-the-type-of-an-implicit-global-variable-for-a-js-code-snip">JSDoc: How to specify the type of an implicit global variable for a JS code snippet?</a></li>
  <li>This is why i tried <code>@var</code>: <a href="https://stackoverflow.com/questions/7496732/specify-type-of-globals-declared-in-another-file">Specify type of globals declared in another file</a></li>
  <li>I feel like this <em>could potentially</em> answer my question, but i don't understand the answer: <a href="https://stackoverflow.com/questions/62024218/how-to-document-the-type-of-a-global-variable-with-jsdoc">How to document the type of a global variable with JSDOC</a></li>
  </ul>