-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
885df75
commit 666d203
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type User = { | ||
id: number; | ||
name: string; | ||
email: string; | ||
}; | ||
|
||
// You can omit properties which don't exist! | ||
type UserWithoutPhoneNumber = Omit<User, "phoneNumber">; | ||
|
||
// But you CAN'T pick properties which don't exist | ||
type UserWithOnlyPhoneNumber = Pick< | ||
User, | ||
// @ts-expect-error | ||
"phoneNumber" | ||
>; |
7 changes: 7 additions & 0 deletions
7
src/020-objects/065.5-omit-and-pick-cant-discribute.explainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type DistributiveOmit<T, K extends PropertyKey> = T extends any | ||
? Omit<T, K> | ||
: never; | ||
|
||
type DistributivePick<T, K extends keyof T> = T extends any | ||
? Pick<T, K> | ||
: never; |