# TSR0301: Non-null assertion is not allowed in sound mode. Narrow '…' with a check, or use 'expect(…, "why")'.

> A non-null assertion '!' is used in a sound file. Narrow the value with a check, or use expect(value, "why") from @ts-r.dev/guard.

## What it means

The postfix `e!` is an unchecked claim that a value isn't `null` or `undefined`, so it isn't allowed in sound files, whatever the type of `e`. A `!` on a value that is already non-nullable is reported too: it's harmless today but becomes a lie after a refactor. Definite assignment (`x!: T`) is a different rule ([TSR0801](https://ts-r.dev/errors/TSR0801/)).

## Example

```ts
// Asserting an index is in range.
const names: string[] = ["a"];
export const first: string = names[0]!.trim(); // @expect TSR0301
```

## How to fix

- Narrow with a check: `const el = document.getElementById("app"); if (el) { ... }`.
- Use `expect(value, "why it is set")` from `@ts-r.dev/guard`, which returns the non-null value and throws at runtime if it's missing.
- Delete the `!` when the operand is already non-nullable.

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/TSR0301/
