-
-
Notifications
You must be signed in to change notification settings - Fork 230
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 hasProperty, hasDefinedProperty, hasValorizedProperty and PossibleKeys #191
base: master
Are you sure you want to change the base?
Conversation
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.
Hey @raythurnevoid thanks a lot for your contribution. It looks amazing.
I have a couple of suggestions regarding the naming conventions of this project to keep consistency :)
If you could apply comments I would be more than happy to merge and release :)
Optionally you could put yourself or sources in the jsdocs credits :)
Thank you :)
@@ -226,6 +230,48 @@ const consumer = (param: Nullish | string): string => { | |||
}; | |||
``` | |||
|
|||
### `hasProperty` |
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.
looks great
} | ||
``` | ||
|
||
### `hasValorizedProperty` |
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.
I'm gravitating towadrs hasNonEmptyProperty
WDYT?
### `PossibleKeys<T>` | ||
|
||
Similar to [`$Keys`](#keyst) or `keyof`, but get keys also from union types | ||
|
||
**Usage:** | ||
|
||
```ts | ||
type Props = { name: string; employeeId: string } | { name: string; guestId: string }; | ||
// Expect: "name" | "employeeId" | "guestId" | ||
type PropsKeys1 = PossibleKeys<Props>; | ||
// Expect: "name" | ||
type PropsKeys2 = $Keys<Props>; | ||
// Expect: "name" | ||
type PropsKeys3 = keyof Props; | ||
``` | ||
|
||
[⇧ back to top](#table-of-contents) | ||
|
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.
we already have another proposal for this type called UnionKeys.
I layed out specs there which are not respected here so I propose either:
- update this PR according to specs
- remove this type from this PR
Description
Add 3 new objects related functions and 1 new utility type for union types:
hasProperty
Check if the object has the property, similar to the
in
operator'key' in obj
but unexistent properties are not allowed and it allows intellisenseUsage:
hasDefinedProperty
Check if the object has the property and it is not
undefined
Usage:
hasValorizedProperty
Check if the object has the property and it is not
undefined
and notnull
Usage:
PossibleKeys<T>
Similar to
$Keys
orkeyof
, but get keys also from union typesUsage:
Related issues:
Checklist
For bugfixes:
For new features:
dts-jest