#3Medium

Omit

Implement the built-in `Omit<T, K>` generic without using it. Learn union type manipulation in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement the built-in Omit<t, k> generic without using it.

You'll learn about union type manipulation, essential skills for advanced TypeScript development and type-level programming.

Challenge Instructions: Omit

Medium

Implement the built-in Omit<T, K> generic without using it.

Constructs a type by picking all properties from T and then removing K

For example

interface Todo {
title: string
description: string
completed: boolean
}
 
type TodoPreview = MyOmit<Todo, 'description' | 'title'>
 
const todo: TodoPreview = {
completed: false,
}

Change the following code to make the test cases pass (no type check errors).

Loading...

Video Walkthrough

Detailed Explanation

To omit properties from a type, we combine Pick and Exclude:

type MyOmit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>

How it works:

To make it work without any built-in utility types, we need to use the keyof operator to get the keys of the type T and the Exclude operator to exclude the keys in K.

type MyOmit<T, K extends keyof T> = {
  [P in keyof T as P extends K ? never : P]: T[P]
}

How it works:

This challenge helps you understand union type manipulation and how to apply this concept in real-world scenarios.

This challenge is originally from here.

Share this challenge

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount