Skip to content

Commit

Permalink
2023-08-16T09:20:47.833Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Aug 16, 2023
1 parent 885df75 commit 666d203
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts
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"
>;
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;

0 comments on commit 666d203

Please sign in to comment.