- Sound mode S-03, pre-alpha
- Design record 0007, Accepted
TSR0301
Non-null assertion is not allowed in sound mode. Narrow '{0}' with a check, or use 'expect({0}, "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.
Rule S-03: No non-null assertions (level: sound). Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.
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).
Example
// 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 (accepted 2026-10-15).