Typescript jest global variable example

Viewed 5494
3 Answers

in ts-jest it's necessary to wrap some config values with "ts-jest":

  "jest": {
    "globals": {
      "ts-jest": {
        "__DEV__": true
      }
    }
  }

and can access in code with:

console.log((global as any).__DEV__

Found the answer here https://kulshekhar.github.io/ts-jest/docs/

One proper solution is to write a .d.ts which introduces declare of global variable, and let tsconfig.json inclues this .d.ts file.

I agree that proper solution is to create your custom.d.ts file and declare a global variable there.

Here is how to do that

Related