Codington
0 of 6 problems solved0%

Type Aliases

6 exercises

Type aliases give a name to any type so you can reuse it throughout your code:

type UserId = string | number; type Status = 'idle' | 'loading' | 'success' | 'error'; type Point = { x: number; y: number };

This improves readability, reduces duplication, and keeps APIs consistent.

You can create aliases for:

  • Unionsstring | number or 'red' | 'green' | 'blue'
  • Object shapes{ id: number; name: string }
  • Tuples[number, number] for fixed-length arrays
  • Function signatures(x: number) => number

In this category, you'll:

  • Create type aliases for common patterns in your code
  • Use literal unions for small state sets (status, direction, etc.)
  • Apply aliases across multiple functions to reduce duplication
  • Work with optional and readonly properties in aliases

Keep implementations simple, avoid mutation unless required, and use narrowing to work safely with unions.

CodingtonCodington

© 2025 Codington. Built with TypeScript, TanStack Start and a lot of console.log().