Jmedeiros, this site is for Portuguese questions only.
If I understand your code intuition correctly, you are trying to create a function that takes the name of a property, and returns another function to capture the value of that property of the objects passed to it, correct?
What you are trying to do can be obtained with the following code:
function pickProp<T extends string | number | symbol>(prop: T) {
return function<V extends {[key in T]: any}>(obj: V) {
return obj[prop]
}
}
Note that K
(or key
) is not one of the values of keyof T
, K
is a value of T
, for T
is property itself, not an object.
I also needed to ensure that T
must be the type string
, number
or symbol
, because these are the types of properties valid for an object, otherwise the generic object {[key in T]: any}
would not be valid,