Type Narrowing
Type Narrowing refines search queries by suggesting more specific types of content, boosting relevance and saving you time finding exactly what you need.
Install on your platform
We auto-selected Claude Code based on this skill’s supported platforms.
Run in terminal (recommended)
claude mcp add type-narrowing npx -- -y @trustedskills/type-narrowing
Or manually add to ~/.claude/settings.json
{
"mcpServers": {
"type-narrowing": {
"command": "npx",
"args": [
"-y",
"@trustedskills/type-narrowing"
]
}
}
}Requires Claude Code (claude CLI). Run claude --version to verify your install.
About This Skill
What it does
The type-narrowing skill allows an AI agent to refine the type of a variable within TypeScript code. This process involves using techniques like conditional checks, discriminated unions, and type predicates to ensure that variables are treated as more specific types than initially declared. The goal is to improve code safety and enable more precise operations on data.
When to use it
- Handling union types: When a variable can be one of several types (a union), this skill helps determine the exact type at runtime for targeted processing.
- Working with discriminated unions: To safely access properties unique to specific members within a discriminated union.
- Refining
anytypes: To gradually eliminateanyand improve type safety in legacy codebases. - Implementing complex conditional logic: When TypeScript's type system needs assistance to correctly infer the type of a variable based on runtime conditions.
Key capabilities
- Conditional Type Narrowing
- Discriminated Union Handling
- Type Predicates
- Runtime Type Checks
Example prompts
- "How can I narrow the type of
datawhich is declared asstring | numberto anumberif it's greater than 10?" - "I have a discriminated union with a 'kind' property. How do I access properties specific to each kind safely?"
- “Explain how to use a type predicate in TypeScript.”
Tips & gotchas
This skill requires a basic understanding of TypeScript’s type system and the concepts of unions, intersections, and generics. Incorrect usage can lead to runtime errors if the narrowing logic is flawed.
Tags
TrustedSkills Verification
Unlike other registries that point to live repositories, TrustedSkills pins every skill to a verified commit hash. This protects you from malicious updates — what you install today is exactly what was reviewed and verified.
Security Audits
| Gen Agent Trust Hub | Pass |
| Socket | Pass |
| Snyk | Pass |
🌐 Community
Passed automated security scans.