TypeScript
Type annotations, interfaces, generics, utility types, and advanced TypeScript patterns.
Basic Types
2 topics
Primitive Types
TypeScript basic primitive types and type annotations
// Basic types
let name: string = "John"
let age: number = 30
let isActive: boolean = true
let value: any = "anything"
// Arrays
let numbers: number[] = [1, 2, 3]
let names: Array<string> = ["Alice", "Bob"]
// Tuple
let tuple: [string, number] = ["hello", 10]
// Enum
enum Color { Red, Green, Blue }
let color: Color = Color.Green💡 Use unknown instead of any when possible
📌 const assertions create readonly literal types
Type Aliases & Unions
Create custom types with aliases and combine with unions
// Type alias
type ID = string | number;
// Union (one of)
type Status = "active" | "inactive" | "pending";
// Intersection (combine all)
type Employee = Person & { company: string };
// Literal types
type Direction = "up" | "down" | "left" | "right";💡 Union (|) means one of these
📌 Intersection (&) means all of these combined
Interfaces
1 topic
Interface Declaration
Define object shapes with interfaces
interface User {
id: number;
name: string;
email?: string; // Optional
readonly createdAt: Date; // Cannot be changed
}
// Extending interfaces
interface Admin extends User {
permissions: string[];
}
// Index signatures
interface Dictionary {
[key: string]: string;
}💡 Interfaces can be extended, types use intersection
📌 Use readonly for immutable properties
Generics
1 topic
Generic Functions & Types
Write reusable code with type parameters
// Generic function
function identity<T>(arg: T): T {
return arg;
}
// Generic interface
interface Box<T> {
value: T;
}
// Constraints
function getLength<T extends { length: number }>(item: T): number {
return item.length;
}
// Multiple type params
function pair<K, V>(key: K, value: V): [K, V] {
return [key, value];
}💡 Use constraints to limit generic types
⚡ Generics enable type-safe reusable code
Utility Types
1 topic
Built-in Utility Types
Transform types with TypeScript's built-in utilities
// Partial - all properties optional
type PartialUser = Partial<User>;
// Required - all properties required
type RequiredUser = Required<User>;
// Pick - select specific properties
type UserName = Pick<User, "name" | "email">;
// Omit - exclude properties
type UserWithoutId = Omit<User, "id">;
// Record - key-value mapping
type Roles = Record<string, string[]>;
// ReturnType
type Fn = () => string;
type Result = ReturnType<Fn>; // string💡 Combine utility types for complex transformations
📌 Partial is great for update functions
Related Cheat Sheets
More hands-on references connected to this topic.
Schema declaration, validation, type inference, transformations, and error handling.
shared topics, same difficulty
Runtime commands, package management, bundling, testing, and performance optimization.
shared topics, same difficulty
Node.js modules, file system, HTTP servers, streams, events, and npm ecosystem essentials.
shared topics, same difficulty
Promises, async/await, error handling, parallel execution, and common async patterns.
shared topics
Related Articles
Background reading and deeper explanations for this sheet.
Build an Agentic App with FastAPI and Azure AI Foundry: A Practical Beginner-to-Pro Guide
Learn how to design, build, and deploy an agentic application using FastAPI and Azure AI Foundry with practical, real-world examples. This guide walks you from architecture and setup to tool-calling, memory, observability, and production deployment patterns.
keyword overlap
System Design for 100 Million Requests/Day: Scalable Patterns Made Simple
Designing for 100 million requests a day sounds intimidating, but it becomes manageable when you break traffic into layers and apply proven patterns. In this guide, you’ll learn the architecture, capacity math, and practical system design patterns—like caching, queue-based load leveling, and CQRS—with easy examples you can reuse.
keyword overlap
Agent Routing vs Model Routing: Real Production Patterns, Tradeoffs, and Implementation Guide
Choosing between agent routing and model routing can make or break your AI product’s cost, speed, and reliability. In this practical guide, you’ll learn what each pattern is, when to use it, and how production teams combine both to ship robust systems. We’ll walk through real examples, architecture patterns, and code you can adapt immediately.
keyword overlap
AI Helped Me Build 100 Features. It Didn't Bring Me 100 Users.
AI made me faster than ever at building software. Then I opened analytics and realized my biggest bottleneck had moved.
keyword overlap