Types

1 min read
Rapid overview

Type Choices in JavaScript/TypeScript

Use these notes to explain when to use types, interfaces, and classes in TS.


Type vs interface

  • Type aliases: Great for unions, primitives, and utility types.
  • Interfaces: Good for object shapes and extension via declaration merging.
type Status = 'idle' | 'loading' | 'error';

interface User {
  id: string;
  name: string;
}

Classes

  • Use for stateful logic or when you need instanceof checks.
  • Keep constructors simple; move side effects elsewhere.

Generics

  • Apply generics to make utilities reusable.
const identity = <T>(value: T): T => value;

Interview prompt

  • When do you prefer type over interface and why?