Skip to content

Conversation

som-sm
Copy link
Collaborator

@som-sm som-sm commented Aug 26, 2025

Fixes #1217

RequiredDeep currently removes all undefineds, so RequiredDeep<{a: string | undefined}> returns {a: string}, even though a is not optional. But IMO, it should only affect optional properties similar to how the built-in Required utility works.

If there's a request, we can consider adding an option to remove undefineds as well, but that shouldn't be the default behaviour.

This PR:

  • Refactors RequiredDeep to only operate on optional properties.
  • Removes all the existing tests because most of the current cases have | undefined attached to them.
  • Adds more test cases, improving the coverage.

@som-sm som-sm force-pushed the fix/required-deep-should-not-remove-undefined branch from 1b72907 to 6def351 Compare August 28, 2025 16:08
@som-sm som-sm force-pushed the fix/required-deep-should-not-remove-undefined branch from 6def351 to d1bc80e Compare August 28, 2025 16:42
@som-sm som-sm marked this pull request as ready for review August 28, 2025 16:45
@som-sm som-sm requested a review from sindresorhus August 28, 2025 16:45
@sindresorhus sindresorhus merged commit bfcdbc4 into main Aug 30, 2025
6 checks passed
@sindresorhus sindresorhus deleted the fix/required-deep-should-not-remove-undefined branch August 30, 2025 07:26
@sindresorhus
Copy link
Owner

Looks good. Thanks for fixing 👍

Hope you had a great summer.

@som-sm
Copy link
Collaborator Author

som-sm commented Aug 31, 2025

I did! Hope yours was great as well 🙂

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.

RequiredDeep should only remove undefined if optional and without exactOptionalPropertyTypes
2 participants