-
Notifications
You must be signed in to change notification settings - Fork 23
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
fix(propEq): improve propEq typings #72
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,31 @@ | ||||||||||||||||||||||||||||||
export function propEq<T>(val: T): { | ||||||||||||||||||||||||||||||
<K extends PropertyKey>(name: K): (obj: Record<K, T>) => boolean; | ||||||||||||||||||||||||||||||
<K extends PropertyKey>(name: K, obj: Record<K, T>): boolean; | ||||||||||||||||||||||||||||||
import { Placeholder } from 'ramda'; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export function propEq(__: Placeholder): never; | ||||||||||||||||||||||||||||||
export function propEq<V>(val: V): { | ||||||||||||||||||||||||||||||
<K extends PropertyKey>(name: K): (obj: Record<K, any>) => boolean; | ||||||||||||||||||||||||||||||
<U extends Record<PropertyKey, any>>(__: Placeholder, obj: U): (name: keyof U) => boolean; | ||||||||||||||||||||||||||||||
<K extends keyof U, U extends Record<PropertyKey, any>>(name: K, obj: U): boolean; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
export function propEq<T, K extends PropertyKey>(val: T, name: K): (obj: Record<K, T>) => boolean; | ||||||||||||||||||||||||||||||
export function propEq<K extends keyof U, U>(val: U[K], name: K, obj: U): boolean; | ||||||||||||||||||||||||||||||
export function propEq<K extends PropertyKey>(__: Placeholder, name: K): { | ||||||||||||||||||||||||||||||
(__: Placeholder, obj: Record<K, any>): <V>(val: V) => boolean; | ||||||||||||||||||||||||||||||
<V>(val: V, obj: Record<K, any>): boolean | ||||||||||||||||||||||||||||||
<V>(val: V): (obj: Record<K, any>) => boolean | ||||||||||||||||||||||||||||||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
export function propEq<V, K extends PropertyKey>(val: V, name: K): (obj: Record<K, any>) => boolean; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export function propEq<U extends Record<any, any>>(__: Placeholder, ___: Placeholder, obj: U): { | ||||||||||||||||||||||||||||||
(__: Placeholder, name: keyof U): { | ||||||||||||||||||||||||||||||
(__: Placeholder): never; | ||||||||||||||||||||||||||||||
<V>(val: V): boolean; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
<V>(val: V, name: keyof U): boolean; | ||||||||||||||||||||||||||||||
(__: Placeholder): never; | ||||||||||||||||||||||||||||||
<V>(val: V): (name: keyof U) => boolean; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my main comment, I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to demonstrate in my main comment that this kind of typing is more likely to create more unnecessary obstacles, rather than help developers catch errors in the early stage |
||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
Comment on lines
+17
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overload order +
Suggested change
|
||||||||||||||||||||||||||||||
export function propEq<K extends PropertyKey>(__: Placeholder, name: K, obj: Record<K, any>): { | ||||||||||||||||||||||||||||||
(__: Placeholder): never; | ||||||||||||||||||||||||||||||
<V>(val: V): boolean; | ||||||||||||||||||||||||||||||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside from my personal opinion about the usefulness of It has to do with overloads and generics, see here: #54 So there is a need to remove all instances of See it in action against your changes here: https://tsplay.dev/W4an4w
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
export function propEq<V, U extends Record<any, any>>(val: V, __: Placeholder, obj: U): (name: keyof U) => boolean; | ||||||||||||||||||||||||||||||
export function propEq<V, U extends Record<any, any>>(val: V, name: keyof U, obj: U): boolean; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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 makes sense to me, however I'm not sure how necessary it it
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.
It might be a bit extra, but it can save from misusing the placeholder