typescript-interface-vs-type

Guide TypeScript interface versus type alias usage for object and union types.

5|Updated Oct 17, 2011
One-click install
npx skills add https://github.com/klen/dotfiles --skill typescript-interface-vs-type-klen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-interface-vs-type
Source: https://github.com/klen/dotfiles/tree/main/.config/opencode/skills/typescript-interface-vs-type
Command: npx skills add https://github.com/klen/dotfiles --skill typescript-interface-vs-type-klen

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the best practices for using interface versus type aliases in TypeScript, helping developers make informed decisions for more robust and maintainable code.

Core Features & Use Cases

  • Guidance on Usage: Provides clear rules on when to prefer interface (object types, extensions, classes) and when to use type (unions, mapped types, tuples).
  • Extending Types: Recommends interface extends over type intersections (&) for better error messages and performance.
  • Use Case: When defining a new data structure for a user profile, decide whether to use an interface or a type alias based on its properties and potential for extension.

Quick Start

Use this skill to understand when to use interface versus type in TypeScript.

Frequently Asked Questions about typescript-interface-vs-type

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

FAQPage Schema
Should I use interface extends or type intersections for extending TypeScript types?

Prefer `interface extends` over type intersections (`&`) when extending TypeScript object types, because it provides improved error messages and better TypeScript performance.

What is the best way to define a new data structure for a user profile in TypeScript?

Yes, TypeScript type aliases are the recommended approach for defining union types, tuple types, mapped types, and conditional types, while interfaces are reserved for object type definitions.

Why does using interface extends improve TypeScript performance compared to intersections?

When defining a new user profile data structure, decide between a TypeScript interface and a type alias based on its properties, checking if it requires object extension or union and tuple types.

Can I use a TypeScript type alias to define union or tuple types?

Using `interface extends` improves TypeScript performance and error messages because it avoids the complexity of resolving type intersections (`&`), making type checking faster and more accurate.