invariant
CommunityRuntime type safety for nullable values.
AuthorViewableGravy
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This Skill enhances code reliability by replacing unsafe type-only assertions with robust runtime checks, ensuring that nullable values are handled correctly and preventing runtime errors.
Core Features & Use Cases
- Safe Type Narrowing: Use
invariant(value, "message")to assert that a value is not null or undefined at runtime, which also narrows its type in TypeScript. - Avoids Non-Null Assertions: Replaces potentially dangerous
!andasoperators with explicit runtime checks. - Handles Falsy Values Correctly: Provides clear guidance on when to use
invariantversus explicit guard clauses for values like0,"", orfalse. - Use Case: When fetching user data, ensure the user object is present before accessing its properties, preventing application crashes.
Quick Start
Use the invariant skill to assert that the 'user' variable is not null or undefined.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: invariant Download link: https://github.com/ViewableGravy/better-ecs/archive/main.zip#invariant Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 223,000+ vetted skills library on demand.