How to use TypeScript in a Custom Test Environment file in Jest? : <p>I need to enable some global variables to be reachable for my test so I am setting up a Custom Environment to be used in the <code>testEnvironment</code> option in my <code>jest.config.json</code> to achieve that.</p>

<p>For our project we have a TypeScript file that we use for <code>setupFilesAfterEnv</code> option and that works just fine, however the <code>testEnvironment</code> seems to support only ES5. Is there any way to use TypeScript in such option?</p>

<p>I successfully created a Custom Jest Environment using ES5 syntax, however since we are injecting global variables I need TypeScript to also declare a global namespace see: <a href="https://stackoverflow.com/a/42304473/4655076">https://stackoverflow.com/a/42304473/4655076</a>. </p>

<pre class="lang-js prettyprint-override"><code>{
  ///...
  setupFilesAfterEnv: ['&lt;rootDir&gt;/test/setup.ts'], // This works with ts
  testEnvironment: '&lt;rootDir&gt;/test/customJestEnvironment.ts', // This doesn't work with ts
}
</code></pre>
