🐛 Bug Report
I'm writing TypeScript code and I want to use jest with injectGlobals turned off, direclty importing from @jest/global. But when using ts-jest all globals end up being available in the global context anyway.
That makes auto-complete suggest the global version and makes it possible compile any code in the project with the the globals.
Step to Reproduce
https://gist.github.com/biro456/40501e3bc024ba92cd3113a7e99d5ebe
- Install dependencies
- Run
build script
- Run
node sample.js
- Run script
test
TypeScript will compile without errors but sample.js will throw a ReferenceError when executed.
Tests will not error though, which means injectGlobals is being ignored.
Expected behaviour
TypeScript should error when a Jest global is used in any file.
envinfo
System:
OS: Ubuntu 20.04.2 LTS on WSL 2 on Windows 10 Pro 20H2 19042.804
Node version.: 14.15.4
Npm packages:
jest: 26.6.3
ts-jest: 26.5.2
typescript: 4.1.5
The solution would be to remove @types/jest from dependencies, allowing package users to import it only if necessary, and change ts-jest to respect injectGlobals.
I saw that it was #1859 that moved @types/jest to dependencies, so an alternative solution would be needed to avoid breaking Yarn 2 again.
🐛 Bug Report
I'm writing TypeScript code and I want to use
jestwithinjectGlobalsturned off, direclty importing from@jest/global. But when usingts-jestall globals end up being available in the global context anyway.That makes auto-complete suggest the global version and makes it possible compile any code in the project with the the globals.
Step to Reproduce
https://gist.github.com/biro456/40501e3bc024ba92cd3113a7e99d5ebe
buildscriptnode sample.jstestTypeScript will compile without errors but
sample.jswill throw aReferenceErrorwhen executed.Tests will not error though, which means
injectGlobalsis being ignored.Expected behaviour
TypeScript should error when a Jest global is used in any file.
envinfo
The solution would be to remove
@types/jestfrom dependencies, allowing package users to import it only if necessary, and changets-jestto respectinjectGlobals.I saw that it was #1859 that moved
@types/jesttodependencies, so an alternative solution would be needed to avoid breaking Yarn 2 again.