type-narrowing

Community

Safely refine types with conditional checks.

Authorluyi985
Version1.0.0
Installs0

System Documentation

What problem does it solve?

Type narrowing helps TypeScript refine broad union and nullable types based on control flow, reducing unnecessary type assertions and preventing runtime errors.

Core Features & Use Cases

  • Null/undefined checks to narrow types
  • typeof and instanceof guards to discriminate between alternatives
  • Discriminated unions (tagged unions) via kind to narrow to a specific variant
  • Using in operator for property presence checks
  • Throw/Return early patterns to guarantee narrowed types after guard
  • User-defined type guards to extend narrowing

Quick Start

Apply type-narrowing in a function that handles union or nullable values to let TypeScript infer the precise type

Dependency Matrix

Required Modules

None required

Components

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: type-narrowing
Download link: https://github.com/luyi985/lyi-bash/archive/main.zip#type-narrowing

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.