# TSR0401: … (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.

## 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

```ts
// 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](https://github.com/Webb-Ventures/typescript-rust/blob/main/docs/design/0007-sound-mode.md) (accepted 2026-10-15).

Source: https://ts-r.dev/errors/TSR0401/
