Skip to content

Commit

Permalink
SetRequired: Fix performance regression (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjy committed May 30, 2023
1 parent 1fce25c commit 6a82900
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions source/set-required.d.ts
Expand Up @@ -27,8 +27,14 @@ type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
@category Object
*/
export type SetRequired<BaseType, Keys extends keyof BaseType> =
Simplify<
BaseType &
// Pick the keys that should be required from the base type and make them required.
Required<Pick<BaseType, Keys>>
>;
// `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<BaseType, Keys> &
// Pick the keys that should be required from the base type and make them required.
Required<Pick<BaseType, Keys>>
>
: never;

0 comments on commit 6a82900

Please sign in to comment.