From 0b0fff9fca14a77ffb00df9ecd3929f41bde8227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lenoir?= Date: Fri, 26 Apr 2024 16:17:46 +0200 Subject: [PATCH 1/5] feat: add custom omit utility type --- packages/core/src/types.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 24ec45dfff..6a6c1cb83a 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -71,3 +71,15 @@ export type PickUnion = Exclude< UnionType, Exclude >; + +/** + * Also known as mapped type or homomorphic. + * Use this custom Omit utility type to preserve extended Record properties. + * + * Why? Using Omit on extended Records results won't preserve the structure. + * - https://github.com/microsoft/TypeScript/issues/36981 + * - https://github.com/microsoft/TypeScript/issues/54451 + */ +export type OmitAndPreserveStructure = { + [P in keyof T as P extends K ? never : P]: T[P]; +}; From a93c38f3a5969db26c602bb28374177121abeb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lenoir?= <103024358+cf-remylenoir@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:20:34 +0200 Subject: [PATCH 2/5] chore: add changeset --- .changeset/curvy-ladybugs-provide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-ladybugs-provide.md diff --git a/.changeset/curvy-ladybugs-provide.md b/.changeset/curvy-ladybugs-provide.md new file mode 100644 index 0000000000..9b55364cdc --- /dev/null +++ b/.changeset/curvy-ladybugs-provide.md @@ -0,0 +1,5 @@ +--- +"@contentful/f36-core": patch +--- + +feat: add custom omit utility type From 6e5be3d9e2d6107ccc03455445aa95f00f9ae77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lenoir?= Date: Fri, 26 Apr 2024 16:22:48 +0200 Subject: [PATCH 3/5] chore: fix documentation typo --- packages/core/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 6a6c1cb83a..1a97f56479 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -76,7 +76,7 @@ export type PickUnion = Exclude< * Also known as mapped type or homomorphic. * Use this custom Omit utility type to preserve extended Record properties. * - * Why? Using Omit on extended Records results won't preserve the structure. + * Why? Using Omit on extended Records does not preserve the structure. * - https://github.com/microsoft/TypeScript/issues/36981 * - https://github.com/microsoft/TypeScript/issues/54451 */ From 095f546519bc835d637e96a67fd4ea51165c47c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lenoir?= <103024358+cf-remylenoir@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:43:50 +0200 Subject: [PATCH 4/5] chore: fix documentation typo --- packages/core/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 1a97f56479..645d11cd0b 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -73,7 +73,7 @@ export type PickUnion = Exclude< >; /** - * Also known as mapped type or homomorphic. + * Also known as mapped omit or homomorphic. * Use this custom Omit utility type to preserve extended Record properties. * * Why? Using Omit on extended Records does not preserve the structure. From 3f69870a869b0dc1c57a3256f0b4cbf8f6d93056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lenoir?= Date: Mon, 29 Apr 2024 10:07:28 +0200 Subject: [PATCH 5/5] chore: rename type --- packages/core/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 645d11cd0b..4e3cbe3d83 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -73,13 +73,13 @@ export type PickUnion = Exclude< >; /** - * Also known as mapped omit or homomorphic. + * Also known as homomorphic. * Use this custom Omit utility type to preserve extended Record properties. * * Why? Using Omit on extended Records does not preserve the structure. * - https://github.com/microsoft/TypeScript/issues/36981 * - https://github.com/microsoft/TypeScript/issues/54451 */ -export type OmitAndPreserveStructure = { +export type MappedOmit = { [P in keyof T as P extends K ? never : P]: T[P]; };