Safeguard
Developer Tools•

Should you set the tsconfig types option in a Node project?

The tsconfig types option controls which @types packages become globals. Why listing them explicitly keeps a Node service's type surface small and clear.

Safeguard Security Team
3 min read

Yes, usually. The types option lists which @types packages add globals to your project. Setting it to an explicit list, such as node and your test runner, keeps stray packages from adding global names, and it makes the type environment match what you actually run.

What the option does

The TypeScript tsconfig reference says types limits which @types packages are included in the global scope. Its example, "types": ["node", "jest"], loads only those two. The reference adds two details:

  • It does not affect normal imports such as import * as moment from "moment". It controls globals, such as process from Node, and auto import suggestions.
  • The reference says the default is an empty list, and that for versions before TypeScript 6.0 every visible @types package is included by default.

Because the default depends on your compiler version, an upgrade can change which globals exist. Setting the list yourself removes that surprise.

Why it is relevant to hardening

A global type is a name the compiler accepts without an import. If a transitive @types package slips in, code can compile against a global that does not exist in your runtime, such as a browser global in a server build. The result is a runtime failure, or worse, a branch that behaves differently on the server than anyone expected.

There is also a review benefit. An explicit list is a short, visible statement of the environments the project targets. A reviewer can see that a backend service declares node and nothing for the browser.

How to set it

  1. Look at which @types packages are installed: npm ls --all and search for @types/.
  2. Decide which globals your code truly needs. A Node API usually needs node and a test framework.
  3. Add the list to compilerOptions:
{
  "compilerOptions": {
    "strict": true,
    "types": ["node"]
  }
}
  1. Run the compiler. Errors tell you which globals were being supplied implicitly, and you can add those packages to the list or import them directly.
  2. Keep test globals out of your production build by using a second tsconfig for tests that adds the test runner.

A note on dependencies

Type packages are real npm packages and appear in your lockfile and SBOM. They run no code at runtime, but install scripts and ownership changes apply to any package you install, so keep them in the scan scope. Trim ones you do not use.

What it will not do

The option does not stop a package from being installed, and it does not change what Node loads at run time. It only affects what the compiler assumes. Treat it as hygiene, in the same bucket as pinning the package manager.

Safeguard includes @types packages in its dependency inventory and SBOM output, so nothing hides because it is only a type package. Try a free scan.

Quick check

Does the types option block an import of a package?

No. It only limits which type packages add globals, per the TypeScript reference.

What is the default if I do not set it?

The reference says the default is an empty list, and that before TypeScript 6.0 all visible @types packages were included. Check your compiler version.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.