typescript-interface-vs-type

Decide between interface and type for TypeScript object shapes.

280|36|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/flpbalada/my-opencode-config --skill typescript-interface-vs-type
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-interface-vs-type
Source: https://github.com/flpbalada/my-opencode-config/tree/main/skills/typescript-interface-vs-type
Command: npx skills add https://github.com/flpbalada/my-opencode-config --skill typescript-interface-vs-type

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers decide when to use TypeScript's interface vs type alias for object modeling, improving type extensibility and readability.

Core Features & Use Cases

  • Determine when to prefer interface for object definitions, extending objects, and declaration merging.
  • Determine when to prefer type for unions, mapped types, and complex type expressions.
  • Real-world use case: modeling API responses or domain models with clear extensibility and compatibility with existing libraries.

Quick Start

Ask the AI to classify a given object type as interface or type and justify the choice.

Frequently Asked Questions about typescript-interface-vs-type

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 for object shapes?

Use a TypeScript interface for extensible object definitions and declaration merging, while a type alias is better for unions, mapped types, and complex type expressions.

How do I model API responses in TypeScript using interfaces or types?

To model API responses in TypeScript, use an interface if you need library compatibility and future declaration merging, or use a type alias for complex expressions and union structures.

Does TypeScript declaration merging work with type aliases?

TypeScript declaration merging only works with interfaces, allowing multiple same-name interface declarations to combine, whereas type aliases cannot be merged after declaration.

What is the best way to extend object shapes in TypeScript?

The best way to extend object shapes in TypeScript is using interfaces, which support extending multiple interfaces simultaneously and integrate cleanly with existing library definitions.

Can I use TypeScript type aliases for union and mapped types?

TypeScript type aliases are specifically required for creating union types and mapped types, as interfaces cannot express these complex type expressions or conditional type logic.

Why does my TypeScript library type conflict with my custom interface?

Library type conflicts often occur when using type aliases instead of interfaces; interfaces support declaration merging to augment existing library definitions without causing naming conflicts.