definite assignment assertion (!)

Asserts that a variable or property is assigned before use despite analysis.

Since TS 2.7 Spec ↗

Syntax

let name!: Type

Examples

let token!: string;
function init() { token = 'abc'; }
init();
token.toUpperCase();
class Comp {
  @Input() value!: number; // assigned by framework
}

Notes

The postfix `!` on a declaration tells the compiler to skip the strict "used before assignment" / "no initializer" check, asserting that something else guarantees initialization. Distinct from the non-null assertion operator used on expressions. Use sparingly; an unmet assertion fails silently at runtime.

See also