Last updated: Apr 29, 2026

Types

Quick-return cheat sheet for everyday TypeScript types — primitives, objects, literals, and common type expressions.

Built-in Primitives

TypeDescription
booleantrue or false
stringText values
numberIntegers and floats (64-bit IEEE 754)
undefinedVariable declared but not assigned
nullIntentional absence of a value
anyOpts out of type checking entirely
unknownType-safe counterpart of any — must narrow before use
neverValue that never occurs (exhausted unions, functions that throw)
voidFunction returns nothing
bigintArbitrary-precision integers (9007199254740991n)
symbolGlobally unique identifier (Symbol("id"))

Common Built-in Objects

Date, RegExp, Error, URL, ArrayBuffer

Promise<T>, Map<K, V>, Set<T>, WeakMap<K, V>, WeakSet<T>

Array<T> / T[], ReadonlyArray<T> / readonly T[]

Type Literals

type Direction = "north" | "south" | "east" | "west"; // string literal
type DiceRoll = 1 | 2 | 3 | 4 | 5 | 6; // number literal
type Falsy = false | 0 | "" | null | undefined; // mixed literals
type EventName = `on${string}`; // template literal

Type Expressions

// primitive
let name: string = "Alice";

// object literal
type Point = { x: number; y: number };

// tuple - fixed-length array with named elements
type RGB = [red: number, green: number, blue: number];

// union
type Result = "success" | "error";

// intersection
type Timestamped = Point & { createdAt: Date };

// indexed access
type User = { role: "admin" | "viewer"; name: string };
type Role = User["role"]; // "admin" | "viewer"

// type from value
const config = { port: 3000, host: "localhost" };
type Config = typeof config; // { port: number; host: string }

// type from function return
function getUser() {
  return { id: 1, name: "Alice" };
}
type User2 = ReturnType<typeof getUser>; // { id: number; name: string }

// type from module
type Schema = import("./schema").Schema;

Object Type Shape

type AppConfig = {
  /** JSDoc comment attached to show in IDE */
  env: string;

  port?: number; // optional property

  readonly version: string; // readonly property

  format: (input: string) => string; // arrow function

  reset(): void; // method shorthand

  [key: string]: unknown; // index signature
};

Enums

// numeric (auto-increments from 0)
enum Direction {
  Up, // 0
  Down, // 1
  Left, // 2
  Right, // 3
}

// string
enum Status {
  Active = "ACTIVE",
  Inactive = "INACTIVE",
}

// const enum — inlined at compile time, no runtime object
const enum Color {
  Red = "RED",
  Blue = "BLUE",
}