From 6a82900b45c7c2bcf3f5964dd07bc5e8a3999dac Mon Sep 17 00:00:00 2001 From: Andy Young Date: Tue, 30 May 2023 15:29:33 +0100 Subject: [PATCH] `SetRequired`: Fix performance regression (#628) --- source/set-required.d.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/set-required.d.ts b/source/set-required.d.ts index 7acdc50f1..735c227c4 100644 --- a/source/set-required.d.ts +++ b/source/set-required.d.ts @@ -27,8 +27,14 @@ type SomeRequired = SetRequired; @category Object */ export type SetRequired = - Simplify< - BaseType & - // Pick the keys that should be required from the base type and make them required. - Required> - >; + // `extends unknown` is always going to be the case and is used to convert any + // union into a [distributive conditional + // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types). + BaseType extends unknown + ? Simplify< + // Pick just the keys that are optional from the base type. + Except & + // Pick the keys that should be required from the base type and make them required. + Required> + > + : never;