Skip to content

Commit 6a82900

Browse files
authoredMay 30, 2023
SetRequired: Fix performance regression (#628)
1 parent 1fce25c commit 6a82900

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎source/set-required.d.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
2727
@category Object
2828
*/
2929
export type SetRequired<BaseType, Keys extends keyof BaseType> =
30-
Simplify<
31-
BaseType &
32-
// Pick the keys that should be required from the base type and make them required.
33-
Required<Pick<BaseType, Keys>>
34-
>;
30+
// `extends unknown` is always going to be the case and is used to convert any
31+
// union into a [distributive conditional
32+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
33+
BaseType extends unknown
34+
? Simplify<
35+
// Pick just the keys that are optional from the base type.
36+
Except<BaseType, Keys> &
37+
// Pick the keys that should be required from the base type and make them required.
38+
Required<Pick<BaseType, Keys>>
39+
>
40+
: never;

0 commit comments

Comments
 (0)
Please sign in to comment.