Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix breaking performance change in set-required #628

Merged
merged 2 commits into from
May 30, 2023

Conversation

andyjy
Copy link
Contributor

@andyjy andyjy commented May 29, 2023

This PR updates #611 with a better fix that uses a distributive conditional to expand union types.

The original fix released in v3.10.0 is less efficient, producing TS error TS2589: 'Type instantiation is excessively deep and possibly infinite' when applied to my application code (as a result of computing all the intersections of each key in Keys with it's Required<> version).

Fixes #627

use distributive conditional to expand union types as alternative fix for
sindresorhus@9c12497

- but alleviating chance of producing TS error TS2589: 'Type instantiation is excessively deep and possibly infinite'
Comment on lines +30 to +33
// `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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of a distributive conditional achieves the original goal of #611 in a more performant way

Comment on lines +35 to +36
// Pick just the keys that are optional from the base type.
Except<BaseType, Keys> &
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part reinstates the original code prior to #611

@sindresorhus sindresorhus merged commit 6a82900 into sindresorhus:main May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'Type instantiation is excessively deep..' error caused by update to SetRequired<> in v3.10.0
2 participants