Record types should refine Object.values
flex-tjon opened this issue · 2 comments
Flow version: 0.210.0
Expected behavior
When annotating a dictionary as a Record
, calling Object.values
on that dictionary should return whatever the record type is: this is the way Object.values
handles dictionaries that are created using indexed object syntax
Actual behavior
Calling Object.values
returns an array of mixed
elements instead.
Hi, thanks for reporting, and I'm very pleased to see someone already making use of Flow's mapped types in the wild!
This is currently working as intended, though I do understand your frustration. The two object types you show in your example are different despite looking the same. PurchaseTypes
is an indexed object type while PurchaseTypesRecord
gets evaluated to {PERCENT: string, DOLLAR: string, CO2: string}
. We currently have a special case that supports Object.values
in a special way for indexed objects, but that does not apply to objects without indexers.
Record
is special in that it gets rid of the typical reason we give for returning mixed
, which is that inferring arbitrary unions of object values would be very bad for performance, but this would take some non-trivial work to implement.
didn't mean to close, leaving open