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

Add PartialOnUndefinedDeep type #426

Merged
merged 17 commits into from Jul 30, 2022
Merged

Conversation

clemclx
Copy link
Contributor

@clemclx clemclx commented Jul 19, 2022

Closes #399

@sindresorhus
Copy link
Owner

Can you explain why you went with a different implementation than what's in https://stackoverflow.com/a/72320731/64949 ? Just curious how they compare and whether it was an intentional choice.

@sindresorhus
Copy link
Owner

Thanks for contributing. Make sure you read and adhere to: https://github.com/sindresorhus/type-fest/blob/main/.github/contributing.md#submitting-a-new-type

@sindresorhus
Copy link
Owner

You need to add the type to the readme.

test-d/partial-on-undefined-deep.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
@clemclx
Copy link
Contributor Author

clemclx commented Jul 20, 2022

Can you explain why you went with a different implementation than what's in https://stackoverflow.com/a/72320731/64949 ? Just curious how they compare and whether it was an intentional choice.

Hey,
I ended with a different implementation for some reasons :

  • more comprehensive (subjective)
  • avoid the intersection with the "subtype" keeping only required props and a Partial of the whole type (imo, it could lead to some weird behavior with some complex types)
  • recursion : the solution on StackOverflow could be Deep too, but the intersection type with the Partial would mean that recursion would happen two times (in the first type keeping only non optional props and in the Partial retreating the whole type)

This way, I finally implemented it from scratch as I would have done

source/partial-on-undefined-deep.d.ts Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
source/partial-on-undefined-deep.d.ts Outdated Show resolved Hide resolved
Create a type from another type with all keys and nested keys accepting undefined type set to optional.

Use-cases:
- Make all properties of a type that can be undefined optional to not have to specify keys with undefined value
Copy link
Owner

Choose a reason for hiding this comment

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

Can you come up with some more use-cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure to have more use-cases that would be pertinent/understandable for users, let me know if something seems pertinent for you :)

@sindresorhus sindresorhus merged commit 1cbd351 into sindresorhus:main Jul 30, 2022
@sindresorhus
Copy link
Owner

Thanks :)

skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Aug 16, 2022
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
skarab42 pushed a commit to skarab42/type-fest that referenced this pull request Aug 24, 2022
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
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.

Add PartialOnUndefined type
2 participants