Cheat Sheets

TypeScript Cheat Sheet (2026): Types, Interfaces, Generics & Config

By ArpaNeuro Team September 19, 2026
TypeScript cheat sheet JavaScript

A TypeScript cheat sheet maps the type layer on top of JavaScript: annotations, interfaces, unions, generics, and narrowing. The compiler erases types before the browser runs the file. Strict tsconfig options (strict, noUncheckedIndexedAccess) catch the bugs this sheet exists to prevent.

This TypeScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • Annotate: const n: number = 1 — often inferred; annotate public function boundaries.
  • Interface: interface User { id: number; email: string } for object shapes.
  • Type alias: type Id = string | number for unions, tuples, mapped types.
  • Union / narrow: if (typeof x === "string") or in / discriminated kind fields.
  • Generic: function wrap<T>(x: T): T[] — caller infers T.
  • unknown: Safer than any. Narrow before use.
  • as const: Literal types instead of widened string.
  • tsconfig: strict: true, "moduleResolution": "bundler" for Vite/Next.

Copy-paste examples

Function boundary and a discriminated union

Annotate what you export. Infer locals. Discriminated unions beat optional boolean pairs.

export interface User {
  id: number;
  email: string;
}
export type LoadState =
  | { status: 'idle' }
  | { status: 'loading' }
  | { status: 'ok'; user: User }
  | { status: 'err'; message: string };

export function label(state: LoadState): string {
  switch (state.status) {
    case 'ok':
      return state.user.email;
    case 'err':
      return state.message;
    default:
      return '…';
  }
}

Common mistakes

  • any on every API response because you did not write an interface.
  • Using as assertions to silence errors instead of narrowing.
  • enum for every constant union when a string literal union would serialize cleaner.
  • Shipping tsc skipLibCheck plus broken types and blaming the language.

FAQ

  1. Does TypeScript run in the browser? No. It compiles to JavaScript. Source maps help you debug the TS you wrote.
  1. interface vs type? Interfaces merge and describe objects well. Type aliases handle unions and mapped types. Both are fine for props.
  1. Do I need classes? No. Functions plus interfaces cover most app code. Classes are useful for framework plugins and native-ish APIs.

Related TypeScript cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →