Generic constraint wipes out precise key type #56912
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
generic, constraint, key in, key, mapped types
π Version & Regression Information
β― Playground Link
link
π» Code
π Actual behavior
You can see that in certain scenarios the exact key type of the mapped type degrades back to
string
.π Expected behavior
The exact key type should always be preserved.
Additional information about the issue
The last working version is a fine workaround that I ended up using(edit: it broke things down the line, see @Andarist's proper fix until a fix comes out in the compiler), but I though I'd share the issue anyway, as the "assign to variable and get a different type" is extremely surprising for me (I also tried to find this in FAQ).The text was updated successfully, but these errors were encountered: