• Sound mode S-04, pre-alpha
  • Design record 0007, Accepted

TSR0401

{0} (sound mode enables 'noUncheckedIndexedAccess': indexed reads can be 'undefined').

Sound mode turned on noUncheckedIndexedAccess, so an indexed read can be undefined. Handle the undefined case or iterate instead.

Rule S-04: Checked index access and exact optional properties (level: strict). Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.

What it means

Sound and strict files are checked with noUncheckedIndexedAccess: reading a[i] on an array or an index signature gives T | undefined. When only sound mode turns the flag on, tsc's error for it is reported with this code and tsc's message in {0}. If the tsconfig already sets the flag, tsc's own code is reported instead.

Example

Spec case from design record 0007 (checked by the record's case harness, not by this site's build)
// An array element read as if it always exists.
const names: string[] = ["a"];
export const first: string = names[0]; // @expect TSR0401

How to fix

  • Supply a default: names[0] ?? "none", or use optional chaining.
  • Iterate instead of indexing: for (const n of names) or entries().
  • Use expect(xs[i], "why it exists") when the index is known to be in range.
  • Or turn the flag on in tsconfig.json so the error keeps tsc's code.

Sound mode is defined in design record 0007 (accepted 2026-10-15).