ts-jest: type changes not updated during watch mode

Issue

When you make changes to the types, e.g. renaming a type, the changes cause the test to fail, even if the change actually works fine.

Need to quit jest watch and start again for the changes to be picked up correctly.

causes

My guess is that during rename, multiple files are affected and ts-jest only detect one file has been changed, so the cache of other files are not invalidated, thus containing outdated information.

This happens whenever I make changes to multiple files and save them at the same time.

Another example would be moving a type from one file to another.

Minimal repo

I encounter this in multiple situations. For example, https://github.com/unional/progress-str

To reproduce the issue, you need to run the test in watch mode (npm run watch in the repo above), and then make some changes such as rename or move types.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 24
  • Comments: 31

Commits related to this issue

Most upvoted comments

Also running into this issue with the most recent version of ts-jest (28.0.3), please consider reopening this issue until it is fixed. Thanks a lot.

Having this too. Might this issue be reopened ?

I have this issue too with ts-jest 27.0.7

Still seeing this on ts-jest 27.0.7 and jest 27.2.5. During watch, ts-jest is throwing an error saying that a certain file doesn’t export a type, but it does. When I kill the watch and restart it, the issue is fixed.

v27 😃 currently working on support jest 27 too. So when jest 27 is out, ts-jest will follow

I stumble upon of similar issue. And I guess I have an explanation of what’s going on.

As you may know TS type information only exists during development and removed upon compilation. Jest compiles files one by one and stores result in cache.

Now consider following example:

File1: type definitions File2: imports File1

Run tests. All is OK. Jest will cache compiled File1 and File2.

Scenario 1:

Change File1 and break type (rename, change signature, etc.). What will happen? File2: still the same, cached version is used. Therefore tests are green.

Scenario 2:

Now change File1 and File2. Save them both together. File2: new, Jest will compile it. File1: new, Jest will compile it. TS will pickup breaking change reporting an error.

Workaround: use --no-cache when running tests.

ts-jest 29.0.5 here, same issue

Hi @ahnpnl , I’m not sure if this wasn’t actually fixed or if it is a regression. I recall this not being an issue a few months ago. There are some other issues related to this. Shall I create a new one? Or could you to reopen this?

What I experience is that type changes are not picked up anymore when running jest --watch. Passing --no-cache is not fixing it either. I’ve tested with the currently latest version 27.0.7.

omg i just had this problem, arrives here after googling, saw you fixed it 5 hours ago: awesome! 🎉

Seeing this issue as well. It’s really frustrating. I can even clear out a whole file that has types and it isn’t picked up.