Safeguard
Developer Tools•

Is TypeScript strict mode a security setting?

TypeScript strict mode is not a security control, but nine of its checks remove common bug classes in Node services. Which flags it turns on and why.

Safeguard Security Team
4 min read

Not directly. Strict mode is a type checking setting, and it does not block attacks. It does turn on nine checks that stop null access, silent any types and unsafe error handling, which are the bugs that often turn into security defects in a Node.js service.

What strict actually turns on

According to the TypeScript tsconfig reference, strict is shorthand for nine options. The page also says future TypeScript versions may add stricter checks under this flag, so the list can grow when you upgrade.

FlagWhat it stops
alwaysStrictEmits "use strict" and parses in strict mode
noImplicitAnyValues that quietly become any
noImplicitThisthis with an unknown type
strictNullChecksUsing a value that may be null or undefined
strictFunctionTypesUnsafe function parameter assignment
strictBindCallApplyWrong arguments to bind, call and apply
strictBuiltinIteratorReturnLoose typing of built-in iterator results
strictPropertyInitializationClass fields that are never set
useUnknownInCatchVariablesTreating a caught error as a known shape

You can switch off individual checks while keeping strict on, which is useful during a migration.

Why this matters for security

Most injection and access control bugs come from data nobody checked. The checks above push you to handle the case where data is missing or has an unexpected type. A missing user object that gets treated as "no restrictions" is a classic example, and strictNullChecks makes the compiler point at it.

What strict mode cannot do is validate input at run time. Types are erased when the code runs, so a request body typed as User is still whatever the caller sent. Pair the compiler with schema validation at every boundary. We cover that gap in Does TypeScript protect a front end from bad data, and the same logic applies to a Node API.

How to adopt it on an existing project

  1. Turn on strict in a branch and count the errors.
  2. If the number is large, enable the individual flags one at a time, starting with noImplicitAny and strictNullChecks.
  3. Fix errors by narrowing, not by adding casts. A cast such as as User tells the compiler to stop checking.
  4. Fail CI on type errors so the setting cannot drift.
  5. Review any remaining any in code that handles request data, tokens or file paths.

Ratcheting this way is better than a flag day, because the errors you fix first are in the code you touch most.

What to avoid

Do not read a clean compile as a clean security review. Strict mode does not know that a string reaches a shell command, or that a path came from a user. Linting rules and scanning cover those cases, and the next posts in this series look at them.

Try it yourself

Open the demo and click through a code scan to see how issues that typing cannot catch, such as unsafe data flows, still show up in findings.

Click through it at your own pace, or open it full screen.

Safeguard runs SBOM and dependency scanning plus reachability analysis on JavaScript and TypeScript projects, and you can try a free scan.

Quick check

Does strict mode include noUncheckedIndexedAccess?

No. It is a separate option that you enable yourself. It is not part of the nine flags in strict.

Can I enable strict mode and still allow a few checks to be off?

Yes. The TypeScript reference says you can turn off individual checks while keeping strict on.

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.