-
Notifications
You must be signed in to change notification settings - Fork 64
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
Better type declaration for prop
function
#241
Comments
I think first case is intended behavior. As #doc says, it can receive non-key property of given pipe([
{ x: 0 },
{ x: 1 },
{ y: 2 },
],
map(
obj => obj.x
)
) And it has fairly nice return type also! #source If you're facing some problem because of unconstrained parameter type, can you tell me so that I can help for another approach? If you want just to restrict key property via function, I recommend this implementation. (Although I'm not sure what you want through this) function getProperty<T, K extends keyof T>(key: K, obj: T): T[K] {
return obj[key]
}
Since const f = () => {}
console.log(Object.getOwnPropertyNames(f)) // ['length', 'name'] After value being initiated from For example: const x = 1 // definetly number literal
x.toPrecision(2) // this is valid
x.foo = 'bar' // this also valid (at least for js) Maybe #this might helps your understanding. |
@mass2527 @Phryxia Since ramdajs also returns the same type, we judged it to be more familiar to users. |
Suggestion
⭐ Suggestion
Better type for
key
parameterCurrently, invalid keys can be passed without any error.
To enhance this, I aim to allow only valid keys, such as "name" or "age" in this context.
Better type for
obj
parameterAdditionally, any value can currently be passed to
obj
as an argument.My goal is to improve this by enforcing that only valid objects can be passed.
💻 Use Cases
The text was updated successfully, but these errors were encountered: