TypeScript Cheat Sheet

Advanced types, interfaces, and TS-specific syntax.

Basic Types

Concept / Tag Code Snippet Description
Union Type
let id: number | string;
Allow multiple types.
Enum
enum Role { Admin, User }
Named constants.

Interfaces

Concept / Tag Code Snippet Description
Interface
interface User {
  id: number;
  name: string;
}
Define object shape.
Readonly
readonly name: string;
Cannot be modified.

Generics

Concept / Tag Code Snippet Description
Generic Fn
function wrap<T>(item: T): T[] { ... }
Reusable type logic.
Type Assertion
const val = someVar as string;
Explicit type casting.

Explore More Cheat Sheets