non-null-assertion

Replace TypeScript non-null assertions with optional chaining and type guards.

3|1|Updated Mar 29, 2026
One-click install
npx skills add https://github.com/ncaq/konoka --skill non-null-assertion
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: non-null-assertion
Source: https://github.com/ncaq/konoka/tree/main/plugins/web-tasuke/skills/non-null-assertion
Command: npx skills add https://github.com/ncaq/konoka --skill non-null-assertion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TypeScript code often relies on the non-null assertion operator (!) which can mask undefined values and lead to runtime errors; this Skill promotes safer coding by eliminating the use of ! and guiding toward safer patterns such as optional chaining and explicit guards.

Core Features & Use Cases

  • Encourages optional chaining, type guards, and nullish checks to safely handle nullable values.
  • Provides guidelines for reviewing TypeScript code to avoid forced null assertions.
  • Helps teams enforce consistent null-safety practices across codebases.

Quick Start

Replace occurrences of the non-null assertion with safe alternatives and validate code paths.

Frequently Asked Questions about non-null-assertion

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid non-null assertions in TypeScript?

Replace the TypeScript non-null assertion operator with optional chaining, type guards, and nullish checks to safely validate nullable values. This enforces explicit null checks and discourages the ! operator in code.

Why does using the exclamation mark in TypeScript cause runtime errors?

The exclamation mark non-null assertion masks undefined values by overriding the compiler, causing potential runtime errors. Applying type guards and explicit null checks safely validates data parsing and UI state handling instead.

What is the best way to enforce null-safety in TypeScript code review?

The best way to enforce null-safety during TypeScript code review is to flag non-null assertions and require optional chaining or type guards. This ensures consistent null-safety practices across utility functions and UI state handling.

Can I use optional chaining and type guards for data parsing in TypeScript?

Yes, you can use optional chaining and type guards for data parsing in TypeScript. They provide explicit null checks for nullable values, replacing non-null assertions to safely handle parsed data and UI state.

When should I not use the non-null assertion operator in TypeScript?

You should not use the non-null assertion operator when handling nullable values in utility functions, data parsing, or UI state. Use explicit null checks and type guards instead to prevent masked undefined runtime errors.