widen-return-type

Preserve narrow TypeScript return types while widening them using overloads.

437|45|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill widen-return-type
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: widen-return-type
Source: https://github.com/ZaxbyHub/opencode-swarm/tree/main/.opencode/skills/generated/widen-return-type
Command: npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill widen-return-type

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When widening a function's return type to support new use cases or extensibility, developers often lose the narrow, precise return types that make TypeScript's type system valuable, leading to unnecessary type errors and reduced code safety for existing function calls.

Core Features & Use Cases

  • Type-Safe Return Type Widening: Uses TypeScript overloads to preserve narrow return types for existing function calls while supporting widened return types for new use cases.
  • Consistent Opt-In Pattern Integration: Follows existing project patterns for tool map constants, conditional agent registration, and feature flag gating to ensure seamless integration with existing codebases.
  • Use Case: Ideal for OpenCode Swarm plugin development or any TypeScript codebase that uses opt-in tool registration and feature flags, where you need to expand function return types without breaking existing type safety for current users.

Quick Start

Ask the AI to apply the widen-return-type skill to update the return type of your existing tool registration function while keeping narrow return types intact for all current tool calls.

Frequently Asked Questions about widen-return-type

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

FAQPage Schema
How do I widen a TypeScript function return type without losing narrow type safety for existing calls?

To widen return types without losing type safety, use TypeScript overloads to preserve narrow return types for existing function calls while supporting expanded return types for new use cases.

Why does widening my return type for feature flags break existing TypeScript type checks?

Widening return types for feature flags breaks type checks because the new broader type overrides the original narrow type, causing type errors. Applying TypeScript overloads keeps the narrow type intact for existing calls.

How do I add conditional tool registration in TypeScript without losing return type precision?

You can maintain return type precision during conditional tool registration by implementing TypeScript overloads that map existing arguments to narrow return types and new arguments to the widened return type.

Can I extend OpenCode Swarm agent configurations with new tools without breaking current type definitions?

Yes, you can extend OpenCode Swarm agent configurations by applying TypeScript overloads to your tool registration functions, ensuring current calls keep narrow return types while new tools use the widened return type.

What is the best way to support an opt-in tool map in TypeScript while maintaining strict type checking?

The best way to support an opt-in tool map while maintaining strict type checking is using TypeScript overloads to declare multiple return type signatures, keeping existing function calls type-safe.

When should I avoid widening a function return type in a TypeScript codebase?

You should avoid widening a function return type if you cannot implement TypeScript overloads, as failing to do so will degrade type safety and cause type errors for existing function calls throughout your codebase.