coderef

TypeScript Quick Reference

TypeScript types: annotations, interfaces, unions, generics, utility types, narrowing and configuration.

8 sections · 52 snippets · updated Oct 14, 2026

Click any snippet to copy it.

Basic types

Annotating values.

  • Primitive types
  • Arrays
  • Tuple
  • Any / unknown
  • Literal types
  • Null and undefined
  • Type inference

Objects & interfaces

Describing object shapes.

  • Type alias
  • Interface
  • Extend an interface
  • Intersection
  • Index signature
  • Record

Functions

Typing parameters and return values.

  • Typed function
  • Arrow function type
  • Optional / default parameter
  • Function type
  • Void and never
  • Overloads

Unions & narrowing

Values that can be several types.

  • Union
  • Narrow with typeof
  • Narrow with in
  • Discriminated union
  • Exhaustive switch
  • Type guard
  • Non-null assertion
  • Type assertion

Generics

Reusable, type-safe code.

  • Generic function
  • Generic type
  • Constraint
  • keyof
  • Generic class

Utility types

Built-in type transformers.

  • All optional / required
  • Read-only
  • Pick / omit fields
  • Function return / parameters
  • Unwrap a promise
  • Remove null
  • Type of a value
  • Const assertion
  • Check without widening

Classes & enums

Object-oriented features.

  • Class with access modifiers
  • Implement an interface
  • Abstract class
  • Enum
  • Union instead of enum

Tooling

Compiler and config.

  • Install
  • Create tsconfig.json
  • Type-check only
  • Strict mode
  • Run a .ts file directly (Node 22.6+)
  • Ignore one line

← All quick references