-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Partial<T, Keys> make only some properties (Keys) optional #53452
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
Comments
Just pointing out, |
How do you know it is rare? Juding from #25760 and how upvotes usually work, I'd say it is fairly much upvoted and in effect, not rare. And it is included in https://github.com/sindresorhus/type-fest#utilities as |
18 upvotes on a nearly 6-year-old feature request (and no dupes other than this one) in a repo as heavily trafficked as TS isn't really that much. |
+75 upvotes, #25760 (comment) in addition to the issue being closed Jul 30, 2018 (meaning many possibly miss it or do not care upvoting), I do not necessarily agree this is in the lows. VS Code, an arguably even higher trafficked repo, automatically moves 20+ upvote issues into their backlog. But if there is a real reason why this is a an unwanted feature, maybe due to other ways to achieve this, I can see is not necessary. |
We don't add utility types to the lib. Twitter thread on why |
tbf, this is a request to enhance an existing utility type. But I figured it would fall under that rationale regardless. |
It wouldn't be possible to change Partial like that; it's homomorphic but the keys-based version by definition isn't. |
Got it. Though "utility types" are already present (https://www.typescriptlang.org/docs/handbook/utility-types.html):
But I am assuming the definition here is that you do not add utility types, that can be constructed from built-in utility types? |
They don't add utility types unless they're required for emit purposes. Most of the utility types present were added before they made this decision, and removing them would be a big unnecessary breaking change. |
Suggestion
Extend https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype from
Partial<T>
toPartial<T, Keys>
. IfKeys
is not specified, it defaults to all keys.🔍 Search Terms
partial
I already found an old, automatically closed issue, here #25760. But I feel like it is warranted to create a new issue as this should be possible to implement without a backwards-incompatible change.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
See above.
📃 Motivating Example
💻 Use Cases
I often have types where I want all properties to be non-optional, but e.g. when reading them for the first time in an API call, or reading a file, some are optional and then I immediately set them to something if they were not included.
The text was updated successfully, but these errors were encountered: