From 9c124971270e1476236af02505b774b5a1521127 Mon Sep 17 00:00:00 2001 From: Migel Hoxha Date: Tue, 2 May 2023 20:35:50 +0200 Subject: [PATCH] `SetRequired`: Fix it incorrectly combining individual key types (#611) --- source/set-required.d.ts | 3 +-- test-d/set-required.ts | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/set-required.d.ts b/source/set-required.d.ts index d25e6e0d8..7acdc50f1 100644 --- a/source/set-required.d.ts +++ b/source/set-required.d.ts @@ -28,8 +28,7 @@ type SomeRequired = SetRequired; */ export type SetRequired = Simplify< - // Pick just the keys that are optional from the base type. - Except & + BaseType & // Pick the keys that should be required from the base type and make them required. Required> >; diff --git a/test-d/set-required.ts b/test-d/set-required.ts index ef8ea690c..4094e9cc9 100644 --- a/test-d/set-required.ts +++ b/test-d/set-required.ts @@ -16,3 +16,7 @@ expectType<{a: number; b: string; c: boolean}>(variation3); // Fail if type changes even if optional is right. declare const variation4: SetRequired<{a?: number; b: string; c?: boolean}, 'b' | 'c'>; expectNotAssignable<{a?: boolean; b: string; c: boolean}>(variation4); + +// Update one required and one optional to required in a union. +declare const variation5: SetRequired<{a?: '1'; b: string; c?: boolean} | {a?: '2'; b: string; c?: boolean}, 'a' | 'b'>; +expectType<{a: '1'; b: string; c?: boolean} | {a: '2'; b: string; c?: boolean}>(variation5);