Type Narrowing

🌐Community
by marius-townhouse · vlatest · Repository

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.

1

Run in terminal (recommended)

terminal
claude mcp add type-narrowing npx -- -y @trustedskills/type-narrowing
2

Or manually add to ~/.claude/settings.json

~/.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 any types: To gradually eliminate any and 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 data which is declared as string | number to a number if 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 HubPass
SocketPass
SnykPass

Details

Version
vlatest
License
Author
marius-townhouse
Installs
4

🌐 Community

Passed automated security scans.