Back to Home
    TypeScriptTypeScript v5.0Intermediate

    TypeScript

    Type annotations, interfaces, generics, utility types, and advanced TypeScript patterns.

    12 min read
    typescripttypesinterfacesgenericsjavascript

    Basic Types

    2 topics

    Primitive Types

    TypeScript basic primitive types and type annotations

    typescript
    // 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

    typescript
    // 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

    typescript
    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

    typescript
    // 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

    typescript
    // 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 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

    107 Sales in 6 Years: The Uncomfortable Math of Building a CodeCanyon Product

    This is a dangerous loop for developers because coding feels productive. Marketing does not always feel productive. You can spend six hours fixing a complex architecture problem and clearly see the result. Spend six hours writing an article, improving a product page, or understanding search intent? Maybe nothing happens today.

    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

    © 2026 codesips.com. All rights reserved.

    Admin Login