DEV Community

es404020
es404020

Posted on

Introduction to Omit typescript utility types

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;
}
Enter fullscreen mode Exit fullscreen mode
  1. Single Omit
type TodoPreview = Omit<Todo, "description">;

const todo: TodoPreview = {
  title: "Clean room",
  completed: false,
  createdAt: 1615544252770,
};

todo;
Enter fullscreen mode Exit fullscreen mode

2.Multiple Omit



type TodoInfo = Omit<Todo, "completed" | "createdAt">;

const todoInfo: TodoInfo = {
  title: "Pick up kids",
  description: "Kindergarten closes at 5pm",
};

todoInfo;




Enter fullscreen mode Exit fullscreen mode

Top comments (0)