Maps are generally safer than records at runtime, but so-called "mapped types" can only be records. As such, I propose this type:
type RecordToMap<T extends Record<PropertyKey, any>> =
UnionToIntersection<ValueOf<{ [k in keyof T]: Map<k, T[k]> }>>;
This gives stricter typing than Map<keyof T, ValueOf<T>>
: rather than Map<'foo' | 'bar', FooType | BarType>
, this gives Map<'foo', FooType> & Map<'bar', BarType>
.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too