TypeScript provides a bunch of built-in utility types globally available.
These utilities allow you to easily manipulate and transform existing types.
They save you from having to rewrite hundreds of nearly identical interfaces.
This greatly speeds up development time in large-scale enterprise projects.
The Partial<T> utility takes an existing type and makes all of its properties optional.
This is exceptionally useful for update functions where only some fields are being modified.
Instead of creating a whole new interface with ?, you just wrap it in Partial.
interface Todo { title: string; desc: string; }
// Both properties are now completely optional!
let updateData: Partial<Todo> = {
title: "New Title"
};
console.log("Update Data:", updateData);
Pick<T, Keys> creates a new type by grabbing only specific keys from an existing type.
Omit<T, Keys> does the exact opposite, it removes specific keys from the type.
These are heavily used to hide sensitive data like passwords from frontend models.
interface User { name: string; age: number; pass: string; }
// Remove 'pass' from the type definition
type PublicUser = Omit<User, "pass">;
const safeUser: PublicUser = { name: "Akash", age: 25 };
console.log("Safe User:", safeUser);
Using utility types vastly reduces the amount of boilerplate code in your project.
Smaller source files are parsed faster by modern bundlers and build tools.
Quick build times keep developers happy and improve the time-to-market for SEO campaigns.
interface Config { url: string; }
// Prevents reassignment after creation
const myConfig: Readonly<Config> = { url: "https://intricatedevo.com" };
// myConfig.url = "http://bad.com"; // Error!
console.log("Config URL:", myConfig.url);
Which utility type makes all properties of an interface optional?
Utility types are powered entirely by Generics under the hood.
Mastering them will make your codebase significantly cleaner and more professional.
Next, we'll dive deeper into types with the keyof operator.