Preparing your workspace
Utility types transform existing types into new useful forms without repeating the original structure.
TypeScript provides utility types such as Partial, Pick, Omit, Record, Readonly, and Required. These are useful when the same domain model is needed in different situations. For example, a complete User type may be required for database results, while a Partial<User> may be useful for update data. Enums are another way to represent named values, although string literal unions are often simpler for many application cases. Type transformations become especially valuable in large applications where models are reused across APIs, forms, and database layers.
A User type can represent a complete database record, while Pick can create a smaller public profile type and Partial can represent update input.
interface User {
id: string;
name: string;
email: string;
role: string;
}
type PublicUser = Pick<User, "id" | "name">;
type UserUpdate = Partial<Pick<User, "name" | "email">>;
const profile: PublicUser = {
id: "u1",
name: "Aman"
};
const update: UserUpdate = {
name: "Aman Kumar"
};The code creates smaller and more flexible types from the original User definition.