Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: Introduce
PickType
#92base: next
Are you sure you want to change the base?
feat: Introduce
PickType
#92Changes from 2 commits
cbd593a
915ffb0
1661465
e571626
0342943
e88944b
5e11e9b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before, why not use invalid values for some of the omitted properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already checked as part of the
validValues
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is only one of the interesting cases with unions (overlap with the same property type) there are other that need to be tested (and some do not work as expected yet):
Pick<{ a: string, b: boolean} | { a: string, b: boolean }, 'a'>
Pick<{ a: string } | { a: boolean }, 'a'>
should accept both astring
and aboolean
fora
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hint, this fails on newlines, but those are presented poorly in the Jest output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method feels kind of familiar, doesn't it? This is currently great to prove the concept. One of the things you had to change here compared to the implementation in
InterfaceType
is that "partial" is now an aspect of a single property, instead of the entire type.I think we should consider refactoring
InterfaceType
to support that as well. All the ingredients are already in place. This could have the following benefits: (I haven't tried it though)PickType
, we can now delegate entirely toInterfaceType
(sometimes combined with aUnionType
when the input type is a union) from within thepick
functionwithOptional
then returns anInterfaceType
instead of anIntersectionType
makes sense I guess?1strictMissingKeys
etcIf we decide to do that, we should do so in another branch. Let's discuss that offline.
Footnotes
Currently, objects with both mandatory and optional properties are implemented as an intersection of one object with the mandatory properties and one object with the optional properties. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nieuwe issue voor aangemaakt #93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, once you distribute over unions in the
pick
function, then all that remains here is object-like types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one I'm using in pick now, but also don't know if it's okay to export just like that.