TypeScript: Utility Types
TypeScript provides several utility types to facilitate common type transformations. Here are some of them with the examples ✨
Wiki topics:
🌐 · Web Development
TypeScript: Utility Types
TypeScript provides several utility types to facilitate common type transformations. Here are some of them with the examples ✨
Partial
lets us make all required fields optional.
type User = {
name: string;
email: string;
age: number;
gender: string;
};
type PartialUser = Partial<User>;
const emptyUser: PartialUser = {};
const partialUser: PartialUser = {
name: "John Doe"
};
Required
lets us make all optional fields required.
type User = {
name: string;
email: string;
age?: number;
gender?: string;
};
type RequiredUser = Required<User>;
const user: RequiredUser = {
name: "Jane Doe",
email: "jane@doe.com",
age: 29,
gender: "female"
};
Pick
lets us pick some fields to create a new type based on an existing one.
type Article = {
title: string;
description: string;
url: string;
image: string;
}
type ArticlePreview = Pick<Article, "title" | "description">;
const articlePreview: ArticlePreview = {
name: "Visiting Ireland? Here’s what the locals love",
description: "Looking for the best castles, golf courses, or restaurants?"
};
Omit
lets us exclude some properties and create a new type based on an existing one.
type Todo = {
title: string;
description: string;
completed: boolean;
createdAt: number;
}
type TodoPreview = Omit<Todo, "description" | "createdAt">;
const todo: TodoPreview = {
title: "Morning 🧘🏻♀",
completed: true
}; 메타데이터
- post_id
- 90d12115b420
- slug
- typescript-utility-types-90d12115b420
- url
- https://medium.com/@kzazarashvili/typescript-utility-types-90d12115b420
- canonical_url
- https://medium.com/@kzazarashvili/typescript-utility-types-90d12115b420
- author_url
- https://medium.com/@kzazarashvili
- status
- ok
- fetched_at
- 2026-06-29 01:02:39