Avatar ·

The ! (exclamation mark) operator in TypeScript: what does it do when accessing a property?

Hi everyone! I recently started learning TypeScript and came across a strange syntax with an exclamation mark. I encountered this code: ```typescript let name: string | null = getUserName(); console.log(name!.toUpperCase()); ``` I understand that `name` can be `string` or `null`. But what does this `!` after `name` do? Without it, TypeScript complains: "Object is possibly 'null'". With it, everything works. Is this some kind of operator? Does it change the type? Or is it just a way to tell the compiler "shut up"? When is it appropriate to use it, and when is it dangerous? I've read about optional chaining (`?.`), but this is a completely different syntax. Can you explain in simple terms what `!` (exclamation mark / bang) does when accessing a member of an object? And how is it different from a regular type assertion using `as`?