Lesson 44 of 55
15 mins readPython Pick and Omit
In Plain English
Pick<T, K> creates a type by picking properties K from T. Omit<T, K> creates a type by picking all properties from T and removing K.
Core Rules to Remember

Pick<T, Keys>: Constructs a subtype containing only the specified property keys.

Omit<T, Keys>: Constructs a subtype with specified property keys excluded.
Live Interactive Example
Hit Run Code to see it liveSelecting and Filtering Properties
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Output Console
Click "Run Code" to view the rendered output.
How it works: Pick extracts only specified keys; Omit strips internal keys.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Omit Database Metadata
Define interface DbRow { id: number; createdAt: string; name: string; email: string }.
Create type CreateUserDto = Omit<DbRow, "id" | "createdAt">.
Create dto: CreateUserDto = { name: "Grace", email: "grace@zencompiler.com" } and print `${dto.name} (${dto.email})`.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.