title: How to declare in initialize global variable in TS-Node?
body: <p>With Webpack:</p>
  <pre class="lang-js prettyprint-override"><code>const WebpackConfig = {
    // ...
    plugins: [
      new Webpack.DefinePlugin({
        __IS_DEVELOPMENT_BUILDING_MODE__: isDevelopmentBuildingMode,
        __IS_TESTING_BUILDING_MODE__: isTestingBuildingMode,
        __IS_PRODUCTION_BUILDING_MODE__: !isDevelopmentBuildingMode &amp;&amp; !isTestingBuildingMode
      })
    ]
  }
  </code></pre>
  <p>Now I'm going to use TS-Node instead of Webpack. TS-Node does not see these constants:</p>
  <pre><code>ErrorsReportingService.ts:35:9 - error TS2304: Cannot find name '__IS_DEVELOPMENT_BUILDING_MODE__'.
  </code></pre>
  <p>How to initialize these globals for TS-Node?</p>
  <p>Off course, typings for these constants are being provided:</p>
  <pre><code>declare const __IS_DEVELOPMENT_BUILDING_MODE__: boolean;
  declare const __IS_TESTING_BUILDING_MODE__: boolean;
  declare const __IS_PRODUCTION_BUILDING_MODE__: boolean;
  </code></pre>
  <p>Please note that I need both Webpack and TSNode.</p>
  <h2>Solution on conceptual level</h2>
  <ol>
  <li>Create file and initialize global variables (like <code>globalThis.__IS_DEVELOPMENT_BUILDING_MODE__ = false</code> ?)</li>
  <li>Tell TSNode to execute this file first.</li>
  </ol>
  <p>Now the question is TSNode allows such things or not.</p>
  <h2>Update</h2>
  <p>My TypeScript lost the declared globals after I placed them inside <code>declare global {}</code>:</p>
  <p><strong>typings.d.ts</strong></p>
  <pre class="lang-js prettyprint-override"><code>declare global {
    let __IS_DEVELOPMENT_BUILDING_MODE__: boolean;
    let __IS_TESTING_BUILDING_MODE__: boolean;
    let __IS_PRODUCTION_BUILDING_MODE__: boolean;
  }
  </code></pre>
  <p>Now compiler does not see them:</p>
  <pre><code>TS2304: Cannot find name '__IS_DEVELOPMENT_BUILDING_MODE__'.
  </code></pre>
  <p><a href="https://i.stack.imgur.com/UqeWW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UqeWW.png" alt="enter image description here" /></a></p>