TypeScript Syntax and Type Operators

! — non-null assertion expression

Postfix ! removes null and undefined from the static type of an expression. It emits no runtime check. If the expression is actually nullish, subsequent property access may throw. Prefer an explicit guard when absence is possible; use an assertion only when an independently established invariant justifies it. This is not the prefix logical negation operator. Example output: "3". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.

Formal Syntax & Structure

typescript syntaxtypescript
const length = maybe!.length;

Working Example

Example Snippettypescript
function length(value: string | undefined) {  return value!.length;}console.log(length("abc"));
TypeScript Reference