From 666d203969c24201d74e84fd6c273b0758aaedba Mon Sep 17 00:00:00 2001 From: Matt Pocock Date: Wed, 16 Aug 2023 10:20:47 +0100 Subject: [PATCH] 2023-08-16T09:20:47.833Z --- .../065.2-no-autocomplete-on-omit.explainer.ts | 15 +++++++++++++++ ...5.5-omit-and-pick-cant-discribute.explainer.ts | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts create mode 100644 src/020-objects/065.5-omit-and-pick-cant-discribute.explainer.ts diff --git a/src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts b/src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts new file mode 100644 index 0000000..4c0ccd0 --- /dev/null +++ b/src/020-objects/065.2-no-autocomplete-on-omit.explainer.ts @@ -0,0 +1,15 @@ +type User = { + id: number; + name: string; + email: string; +}; + +// You can omit properties which don't exist! +type UserWithoutPhoneNumber = Omit; + +// But you CAN'T pick properties which don't exist +type UserWithOnlyPhoneNumber = Pick< + User, + // @ts-expect-error + "phoneNumber" +>; diff --git a/src/020-objects/065.5-omit-and-pick-cant-discribute.explainer.ts b/src/020-objects/065.5-omit-and-pick-cant-discribute.explainer.ts new file mode 100644 index 0000000..a25b577 --- /dev/null +++ b/src/020-objects/065.5-omit-and-pick-cant-discribute.explainer.ts @@ -0,0 +1,7 @@ +type DistributiveOmit = T extends any + ? Omit + : never; + +type DistributivePick = T extends any + ? Pick + : never;