`RegisterUserForm` type walkthrough
Chapter 3: TypeScript for real-world applications
Chapters - Table of contents
After looking at how operates Partial<T> and Omit<T, K>, let's have a final step by step overview of our RegisterUserForm built on top of the User type:
1interface User {
2    id: string,
3    firstName: string,
4    lastName: string,
5}
6
7type RegisterUserForm = Partial<Omit<User, 'id'>>
8
9// First, `Omit<User, "id">` is resolved, which gives:
10type RegisterUserForm = Partial<Pick<User, Exclude<"id" | "firstName" | "lastName", "id">>>
11
12// then, `Exclude<T, U>`, as we saw earlier resolves to:
13type RegisterUserForm = Partial<Pick<User, "firstName" | "lastName">>
14
15
16// Follows, `Pick<T, K>` that resolves to :
17type RegisterUserForm = Partial<{ firstName: string; lastName: string }>
18
19// And finally, `Partial<T>` produces our final type:
20
21// {
22//   firstName?: string
23//   lastName?: string
24// }
25

Next

Let's now cover a more complete example leveraging most of TypeScript's advanced features.
We use cookies to collect statistics through Google Analytics.
Do not track
 
Allow cookies