🟦 TypeScript Generics

Generics make your code more flexible by allowing it to work with any type while preserving type safety. Think of them as "type variables" you can reuse in classes, functions, and interfaces.

📚 Example Code: Generic Function

Console output will appear here...
💡 Use angle brackets <T> to declare a generic type. It can be named anything — T, U, ItemType, etc.

🔧 Generic Function Syntax

📦 Generic Classes Example

class Box {
  value: T;
  constructor(value: T) {
    this.value = value;
  }
  getValue(): T {
    return this.value;
  }
}

const numberBox = new Box(123);
console.log(numberBox.getValue());
  
⚡ You can use generics in functions, classes, and interfaces for reusable, strongly-typed code.