Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Const

noUncheckedIndexedAccess

The noUncheckedIndexedAccess compiler option adds undefined to undeclared indexed properties and array element reads. This makes missing keys and out-of-bounds access visible to the type checker.

Since
TypeScript 4.1

How it works

Enable this compiler option when index signatures or array lookups may refer to missing entries. TypeScript adds undefined to undeclared indexed properties and array elements, requiring a guard or another explicit handling strategy before those values are used.

Syntax

"noUncheckedIndexedAccess": true

Key points

  • An indexed property not explicitly declared in the type is treated as possibly absent.
  • The option affects both property-style and bracket-style access when the accessed member is not known to exist.
  • Array element reads receive the same missing-value scrutiny, helping reveal possible out-of-bounds access.
  • A practical benefit is detecting array lookups that may exceed the valid range.

Common mistakes

  • Turning on this option can expose many new errors, because strict does not enable it automatically.
  • A non-null assertion suppresses the diagnostic without proving that the property exists, so an existence check is safer when absence is possible.

Example: Guard an indexed property

interface EnvironmentVars {
  NAME: string;
  OS: string;
  [propName: string]: string;
}

declare const env: EnvironmentVars;

const nodeEnv = env.NODE_ENV;

if (nodeEnv !== undefined) {
  console.log(nodeEnv.toUpperCase());
}

With the option enabled, an undeclared indexed property can be undefined, so the code narrows it before use.

When to use it

Validate dictionary lookups

An object has a string index signature but only some keys are populated.

Detect possible out-of-bounds reads

Code reads arrays by calculated positions or loops over uncertain bounds.

Strengthen lookup safety

A large codebase wants compiler feedback for missing indexed values.

Interview questions

QWhat does noUncheckedIndexedAccess change for index signatures?

It changes the type of an undeclared property accessed through an index signature by adding undefined. A declared property such as env.NAME keeps its declared string type, while env.NODE_ENV becomes string | undefined.

Follow-up: What happens with arrays? Array indexing is checked more strictly too, so an element read can include undefined even inside a bounds-checked loop.

QWhy is this option not enabled by strict?

The option is not included by strict because it can produce noisy diagnostics in codebases that use broad index signatures. Teams should enable it deliberately and assess whether the additional checks fit their code.

Follow-up: How should code handle a possibly missing value? Narrow it with an existence check, or use a non-null assertion only when the invariant is guaranteed elsewhere.

QWhat kinds of bugs can this option catch?

It helps catch out-of-bounds array access and missing keys represented by an index signature. The compiler models those reads as potentially undefined rather than assuming every lookup succeeds.

Follow-up: Does it change explicitly declared keys? No: declared properties retain their declared types; the added undefined applies to undeclared indexed fields and indexed element reads.

  • index signatures
  • strict
  • non-null assertion operator
  • noPropertyAccessFromIndexSignature

Source: TSConfig Option: noUncheckedIndexedAccess. Checked 2026-10-15.