TypeScript error

TS2582: Test globals without the test runner types

  • Error TS2582
  • Tested with TypeScript 5.9

Test runners such as Jest, Mocha and Vitest (with its globals option) put describe, it and test in the global scope. TypeScript knows these names are usually test globals, so instead of plain TS2304 it reports TS2582, suggesting types to install.

With a types list in the config that leaves the runner out, the same problem is TS2593, whose message adds the step of naming the package in types. Names the checker does not associate with test runners, such as expect, stay TS2304.

At a glance

CodeTS2582
MessageCannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
Also on this page: TS2593 Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
TypeScript's categoryerror
Listed underUnknown names and members
Depends on types
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The messages are TypeScript's own text from its diagnostic messages file (Apache-2.0); {0} is filled in by tsc for each error.

What it looks like

cart.test.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: cart.test.js(2,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. cart.test.js(4,3): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. 6.0.3 : differs, see why TypeScript 6.0.3, run 21 October 2026: differs from 5.9.3. cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. 7.0.2 : differs, see why TypeScript 7.0.2, run 21 October 2026: differs from 5.9.3. cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. checked 21 October 2026
describe("cart", () => {error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
  it("starts empty", () => {error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
    expect([].length).toBe(0);error TS2304: Cannot find name 'expect'.
  });
});
Test globals with no test runner types and no types list.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "typeRoots": ["./node_modules/@types"]
  },
  "include": ["**/*.js"]
}
cart.test.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig. cart.test.js(6,5): error TS2304: Cannot find name 'expect'. checked 21 October 2026
describe("cart", () => {error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
  it("starts empty", () => {error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
    expect([].length).toBe(0);error TS2304: Cannot find name 'expect'.
  });
});
The same file with a types list that leaves the runner out.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["**/*.js"]
}

What causes it

  • The runner's types are not installed, or not loaded: a types list (this site's configs use types: [] or a short list) loads only the packages it names.
  • The test files are checked by a config meant for application code.

How to fix it

Name the runner's global types

Add the runner's global declarations to types: "vitest/globals" for Vitest with globals on, "jest" (with @types/jest installed) for Jest, "mocha" for Mocha. The fixed example uses Vitest, which this site has installed.

cart.test.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
describe("cart", () => {
  it("starts empty", () => {
    expect([].length).toBe(0);
  });
});
The runner's global types named in types.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": ["vitest/globals"]
  },
  "include": ["**/*.js"]
}

Or import the functions

Runners that export them let you write import { describe, it, expect } from "vitest"; (or @jest/globals), which needs no global types at all. The recipe for test files shows both.

About the examples

The first failing example has no types list and points typeRoots at its own empty folder, to stand for a project with no test runner types installed; the second has a types list that leaves the runner out, which is the TS2593 case.

Under TypeScript 6.0 and 7.0

Every example on this page also runs under TypeScript 6.0.3 and 7.0.2 when this site is built. One of them reports something different from 5.9.3, the version the page describes; the ✗ on its badge links to its entry below.

types defaults to an empty list, so the hint names the types field

TypeScript 6.0 and 7.0 · defaults that changed in 6.0

The pattern: A global from a package that is not installed (process, describe, it) in a config that does not set types.

Why: Only the 6.0 default types: [] causes this. The name is still missing in every version, but 6.0 and 7.0 report it with the code and message for a project that lists its types (TS2591 instead of TS2580, TS2593 instead of TS2582), which add "and then add 'node' to the types field in your tsconfig". Source: TypeScript 6.0 release notes: types now defaults to an empty list.

Test globals with no test runner types and no types list cart.test.js

TypeScript 5.9.3
cart.test.js(2,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
cart.test.js(4,3): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
cart.test.js(6,5): error TS2304: Cannot find name 'expect'.
TypeScript 6.0.3differs from 5.9.3
cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
cart.test.js(6,5): error TS2304: Cannot find name 'expect'.
TypeScript 7.0.2differs from 5.9.3
cart.test.js(2,1): error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
cart.test.js(4,3): error TS2593: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
cart.test.js(6,5): error TS2304: Cannot find name 'expect'.

What works in every version: Install the types and name them: "types": ["node"], plus your test runner's.

server.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
const port = Number(process.env.PORT ?? 3000);

export { port };
With @types/node installed (and named in types).
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": ["node"]
  },
  "include": ["*.js"]
}

Gotchas

  • A separate config for tests (jsconfig.test.json extending the main one, with the runner in types) keeps test globals out of application files, so a stray describe in src/ is still caught.

Sources

Last reviewed 21 October 2026.