typescript-interface-vs-type

Explain TypeScript interface versus type usage and best practices.

Updated Nov 28, 2025
One-click install
npx skills add https://github.com/davidsteinberger/dotfiles --skill typescript-interface-vs-type-davidsteinberger
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-interface-vs-type
Source: https://github.com/davidsteinberger/dotfiles/tree/main/opencode/.config/opencode/skills/typescript-interface-vs-type
Command: npx skills add https://github.com/davidsteinberger/dotfiles --skill typescript-interface-vs-type-davidsteinberger

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the often confusing distinction between interface and type in TypeScript, guiding developers on when to use each for optimal code clarity and performance.

Core Features & Use Cases

  • Guidance on Usage: Provides clear rules for when to prefer interface (object types, extensions, class implementations) versus type (unions, mapped types, conditional types, tuples).
  • Best Practices: Recommends using interface extends over type intersections for better error messages and TypeScript performance.
  • Use Case: When defining a new data structure for a user profile, this skill helps you decide whether to use interface or type based on whether you need to extend existing types or use union types.

Quick Start

Use the typescript-interface-vs-type skill to understand when to use interface versus type for defining object types in TypeScript.

Frequently Asked Questions about typescript-interface-vs-type

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

FAQPage Schema
What is the difference between interface and type in TypeScript?

The difference between interface and type in TypeScript is that interfaces are generally preferred for defining object structures and extending classes, while type aliases are required for unions, mapped types, conditional types, and tuples.

When should I use a type alias instead of an interface in TypeScript?

You should use a type alias instead of an interface in TypeScript when defining union types, mapped types, conditional types, or tuples, as these features are not supported by the interface keyword.

Why should I use interface extends instead of type intersections in TypeScript?

You should use interface extends instead of type intersections in TypeScript because it provides improved error reporting during compilation and better performance when resolving complex object structures.

How do I choose between interface and type for a TypeScript object definition?

To choose between interface and type for a TypeScript object definition, use interface for standard object shapes and class implementations, and use type when you need advanced features like unions or mapped types.

Can I use TypeScript interfaces for union types?

No, you cannot use TypeScript interfaces for union types. You must use the type keyword to define union types, mapped types, conditional types, and tuples in your TypeScript codebase.