TypeScript Utility Types

🧰 TypeScript Utility Types
They make your code cleaner, safer, and more maintainable—especially in real projects.
1️⃣ Partial<T>
Makes all properties optional.
📌 Used in update APIs
2️⃣ Required<T>
Makes all properties required.
3️⃣ Readonly<T>
Makes all properties immutable.
4️⃣ Pick<T, K>
Select specific properties from a type.
✔ Reduces data exposure
✔ Common in APIs
5️⃣ Omit<T, K>
Remove specific properties from a type.
6️⃣ Record<K, T>
Creates an object type with fixed keys and same value type.
7️⃣ Exclude<T, U>
Remove types from a union.
8️⃣ Extract<T, U>
Extract matching types from a union.
9️⃣ NonNullable<T>
Removes null and undefined.
🔟 ReturnType<T>
Gets a function’s return type.
1️⃣1️⃣ Parameters<T>
Extracts parameter types as a tuple.
🔑 Utility Types Summary
| Utility | Purpose |
|---|---|
Partial | Optional properties |
Required | Force required |
Readonly | Immutable |
Pick | Select properties |
Omit | Remove properties |
Record | Key-value map |
Exclude | Remove union types |
Extract | Pick union types |
NonNullable | Remove null/undefined |
ReturnType | Function return |
Parameters | Function params |
⭐ Best Practices
✔ Prefer utility types over rewriting interfaces
✔ Use Pick / Omit in APIs
✔ Use Partial for PATCH operations
✔ Combine utility types when needed
