ts-jest: [Bug]: no type check when tsconfig's isolatedModules compiler option is true
Version
29.3.3
Steps to reproduce
- Clone the repro: https://github.com/toomuchdesign/ts-jest-type-check-repro
npm ci
isolatedModules true
npm run test: tests succeednpm run type:check: type check fails
isolatedModules false
- Disable
isolatedModulesintsconfig.json npm run test: tests type check failsnpm run type:check: type check fails
Expected behavior
Type check should be executed at test execution time no matter isolatedModules compiler option.
Actual behavior
Enabling tsconfig’s isolatedModules compiler option seems to cause type check from being executed at test execution time.
Disabling tsconfig’s isolatedModules compiler option, brings type check back.
Debug log
Sorry, the log was too large to make sure it doesn’t expose sensitive information. Happy to provide any relevant extra info.
Additional context
No response
Environment
System:
OS: macOS 14.7.4
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
npmPackages:
jest: ^29.7.0 => 29.7.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 32
We can start doing that by default in the next major version. Currently, you can disable it via
diagnostics: false+isolatedModules: falseorisolatedModules: true.However, whenever using
isolatedModules: false, it always consumes a lot memories and CPU regardless how many workers. This is the cost of using full TypeScriptProgramin combination with using Jest. Like I explained above, the implementation withProgramisn’t exactly the same astsceither, so that’s also something to look at.It’s different between running only
tscvs running Jest + compilation step (done ints-jest). Currently, the only way to get the most performant is usingisolatedModules: trueregardless 1 or many workers.Yes, strictly speaking there are 2 behaviors done by
tscwithisolatedModules: truejslike other transpilers.From the start,
ts-jestintroduced a similarisolatedModulesoption to only replicate the 1st behavior. As codebase has grown, we have decided to simplify the config option by reusing the option fromtsconfigwhile keeping the behavior as is without making breaking change. It was intentional decision.Type checking is an expensive process to do in a worker thread giving the current architecture of TypeScript itself. Porting to Go will help this in the future.
Giving the state of your PR, it is the right direction for implementation 👍 I think to prepare for the switch in the next major version, I would need to prepare a separate PR to indicate a logging about “default value” for
diagnosticsFor now,
ts-jestwill still focus on using TypeScript API. For this request, it’s a simple thing to do with just invokingtscand read from output dir.About other transpilers, those would be new codes and not touching to legacy folder. It’s out of concern for this request 😃
Yes, the only different behavior with
tscis thattscstill offers type checking whilets-jestdoesn’t.In theory it should be possible to add an extra flag for type checking.