avoiding-non-null-assertions
Installation
SKILL.md
Contains Shell Commands
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
Avoiding Non-Null Assertions
The non-null assertion operator (!) is deprecated in modern TypeScript because it bypasses type safety and can lead to runtime errors.
Why Avoid !
- Bypasses type safety: Tells TypeScript "trust me" without verification
- Runtime errors: Can cause
undefinedornullerrors at runtime - Maintenance burden: Makes refactoring dangerous
- No protection: Removes TypeScript's main benefit
Modern Alternatives
1. Optional Chaining (?.)
Bad: