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.
TaskCode
- Primitive types
- Arrays
- Tuple
- Any / unknown
- Literal types
- Null and undefined
- Type inference
Objects & interfaces
Describing object shapes.
TaskCode
- Type alias
- Interface
- Extend an interface
- Intersection
- Index signature
- Record
Functions
Typing parameters and return values.
TaskCode
- Typed function
- Arrow function type
- Optional / default parameter
- Function type
- Void and never
- Overloads
Unions & narrowing
Values that can be several types.
TaskCode
- Union
- Narrow with typeof
- Narrow with in
- Discriminated union
- Exhaustive switch
- Type guard
- Non-null assertion
- Type assertion
Generics
Reusable, type-safe code.
TaskCode
- Generic function
- Generic type
- Constraint
- keyof
- Generic class
Utility types
Built-in type transformers.
TaskCode
- 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.
TaskCode
- Class with access modifiers
- Implement an interface
- Abstract class
- Enum
- Union instead of enum
Tooling
Compiler and config.
TaskCode
- Install
- Create tsconfig.json
- Type-check only
- Strict mode
- Run a .ts file directly (Node 22.6+)
- Ignore one line