-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
PickType and OmitType #50
Comments
I like this types, they are definitely useful. For the name I would propose:
I choose this name because regular pick is picking by key, and Examples: type PickByValue<Base, Condition> = Pick<
Base,
{ [Key in keyof Base]: Base[Key] extends Condition ? Key : never }[keyof Base]
>;
type Props2 = { name: string; 0: boolean };
type SomeProps1 = Pick<Props2, 0>;
// Expect: { 0: boolean }
type SomeProps2 = PickByValue<Props2, boolean>;
// Expect: { 0: boolean } Accepting PR's. |
This PR adds `PickByValue` and `OmitByValue` per #50.
It's merged but I'm blocking the release for the moment. Mainly because there are few other API proposals and until all of them are sorted out I don't want to make a mistake and introduce some breaking changes in the process. |
What happened to these? It looks like they got merged, but then they were removed from |
currently: import { PickByValue, OmitByValue } from 'utility-types/dist/mapped-types' |
I'll have some time during weekend, so hopefully I can finish the proposal for this API and make it public |
@BoostIO has funded $30.00 to this issue.
|
@piotrwitek has rewarded $21.00 to @piotrwitek. See it on IssueHunt
|
Hi,
Could you please add
PickType
andOmitType
types similar toPick
andOmit
. It would be helpful. They pick and omit properties based on types of values instead of key names:I changed names to make it more compatible with
utility-types
. You can change if you have a more appropriate name in your mind.Types
Usage
Types are not developed by me. I saw them on a blog post by Piotr Lewandowski and used in several projects.
Credits: https://medium.com/dailyjs/typescript-create-a-condition-based-subset-types-9d902cea5b8c
Thanks,
The text was updated successfully, but these errors were encountered: