Use TypeScript's built-in utility types to transform existing types.
TypeScript ships with utility types that let you create new types by transforming existing ones. You never need to re-write common patterns.
Partial<T>Makes every property of T optional — great for update payloads:
interface User {
name: string;
age: number;
email: string;
}
type UserUpdate = Partial<User>;
// { name?: string; age?: number; email?: string }
Required<T>The opposite — makes every property required:
type RequiredUser = Required<UserUpdate>;
// { name: string; age: number; email: string }
Pick<T, Keys>Select a subset of properties:
type UserPreview = Pick<User, "name" | "email">;
// { name: string; email: string }
Omit<T, Keys>Drop specific properties:
type PublicUser = Omit<User, "email">;
// { name: string; age: number }
Readonly<T>Prevents any property from being reassigned:
const config: Readonly<User> = { name: "Alice", age: 30, email: "a@b.com" };
config.name = "Bob"; // ❌ Error
Record<Keys, Value>Create an object type with specific keys and a uniform value type:
type ScoreMap = Record<string, number>;
const scores: ScoreMap = { alice: 95, bob: 87 };
Given this interface:
interface Product {
id: number;
name: string;
price: number;
description: string;
}
ProductPreview — a Pick of id and name onlyProductUpdate — a Partial of ProductProductWithoutDesc — an Omit of descriptioncreatePreview(p: Product): ProductPreview that returns just the id and nameinterface Product { id: number; name: string; price: number; description: string; } // 1. export type ProductPreview = Pick<Product, ...> // 2. export type ProductUpdate = Partial<Product> // 3. export type ProductWithoutDesc = Omit<Product, ...> // 4. export function createPreview(p: Product): ProductPreview