The Omit utility construct a type by picking all properties from type and then removing keys. This allows you to remove property from any object .
interface Todo {
title: string;
description: string;
completed: boolean;
createdAt: number;
}
- Single Omit
type TodoPreview = Omit<Todo, "description">;
const todo: TodoPreview = {
title: "Clean room",
completed: false,
createdAt: 1615544252770,
};
todo;
2.Multiple Omit
type TodoInfo = Omit<Todo, "completed" | "createdAt">;
const todoInfo: TodoInfo = {
title: "Pick up kids",
description: "Kindergarten closes at 5pm",
};
todoInfo;
Top comments (1)
Take your TypeScript skills to new heights with "Mastering TypeScript Core Utility Types":
📖 Buy on Leanpub
📖 Buy on Amazon