Hi,
I have a User object:
type User = {
name: string,
};
That has a get() function, that takes in parameter the key of an attribute on User and returns this attribute.
The function get is
User.prototype.get = (prop) => {
return this[prop];
};
How can I write this fonction definition ?
Here's what I got so far:
type User = {
name: string,
get: (k: $Keys<User>) => any, // How can I change any to the correct property type ?
// It would be great if I could do `get: (k: $Keys<User>) => $PropertyType<User, k>`
};
Thanks :)
We all are waiting for https://github.com/facebook/flow/pull/2952 :-)
@agentcooper
Do you know why we still have to wait for this PR? :/
$ElementType<T, K> landed, i guess this issue can be closed :tada:
Most helpful comment
$ElementType<T, K>landed, i guess this issue can be closed :tada: