[Typescript] Tips: Derive a union type from an object
const fruitCounts = {
apple: 12,
banana: 23
}
type PropUnion<T extends Record<PropertyKey, any>> = {
[K in keyof T]: {
[K2 in K]: T[K2]
}
}[keyof T]
type FruitCounts = PropUnion<typeof fruitCounts>