type-vs-interface

Decide between TypeScript interfaces and type aliases for object shapes and unions.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill type-vs-interface
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-vs-interface
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/type-vs-interface
Command: npx skills add https://github.com/luyi985/lyi-bash --skill type-vs-interface

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers decide when to use TypeScript interfaces versus type aliases, reducing confusion and inconsistencies in type design.

Core Features & Use Cases

  • Clear guidance on object types vs non-object types, with rules for when to prefer interface or type.
  • Practical decision scenarios for API surfaces, component props, and library declarations.
  • Quick comparisons of declaration merging, unions, tuples, and mapped types to inform coding standards.

Quick Start

Decide, in your codebase, to use interface for object shapes that can be extended and type for unions, tuples, and mapped types.

Frequently Asked Questions about type-vs-interface

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

FAQPage Schema
When should I use a TypeScript interface vs a type alias?

Use a TypeScript interface for extendable object shapes and a type alias for unions, tuples, and mapped types to ensure consistency and extensibility in your codebase.

How do I choose between type and interface for API design?

For API design, prefer interfaces to define extensible object shapes and use type aliases for complex unions or tuples, enforcing consistency across your API surfaces.

Does TypeScript support declaration merging with type aliases?

TypeScript declaration merging applies only to interfaces, allowing multiple declarations to combine into one, whereas type aliases cannot be merged.

What is the best way to type component props in TypeScript?

The best way to type component props is generally using interfaces for extendable object shapes, reserving type aliases for mapped types or union props.

Can I use type aliases for library declarations in TypeScript?

For library declarations, prefer interfaces for public object shapes to allow consumer extension via declaration merging, using type aliases for internal unions or tuples.