You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to write a generic setter function which receives the property name as a string and the property value as type T which should conform to the type determined by the property name.
Something like this would be nice:
/* @flow */typet={a: string,b: number,}constobj: t={a: "hi",b: 1,};// Syntax error since t[k] doesn't workfunctionchange<k: $Keys<t>>(key: k,value: t[k]){obj[key]=value;}change("a","...");change("b",1324);change("b","...");// should fail
Is there a way to achieve this?
The text was updated successfully, but these errors were encountered:
Thanks for the pointer! I had looked through the utilities, but apparently I overlooked this.
However, I guess, I have to wait until $PropertyType allows the second parameter to be a non-string. Since this is sort of tracked in #2310, I'll close this issue.
I would like to write a generic setter function which receives the property name as a string and the property value as type T which should conform to the type determined by the property name.
Something like this would be nice:
Is there a way to achieve this?
The text was updated successfully, but these errors were encountered: