Coding⏱️ 2 min read📅 2026-05-31

How to Fix: "TS2322: Type 'Timeout' is not assignable to type 'number'" when running unit tests

TS2322 error when running unit tests with npm link

Quick Answer: The issue arises from the way `npm link` affects the package's scope. When you run Package A's unit tests after linking, it uses the global scope of Package B, which includes the `Timeout` type, whereas in standalone test runs, each package has its own isolated scope.

To resolve the "TS2322: Type 'Timeout' is not assignable to type 'number'" error, it is essential to understand why this issue occurs. When you run tests for Package A with npm link package-b, both packages share the same global scope, which can lead to unexpected behavior.

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Use a different scope for setTimeout

  1. Step 1: Modify the test to use a global variable or import it from Package B.

Method 2: Use an isolated scope for setTimeout

  1. Step 1: Create a new test file or use Karma's --single-run flag to run the tests in isolation.

🎯 Final Words

By applying one of these solutions, you should be able to resolve the "TS2322: Type 'Timeout' is not assignable to type 'number'" error and ensure your unit tests run smoothly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions