// https://effectivetypescript.com/2020/05/12/unionize-objectify/ export type Unionize = { [k in keyof T]: { k: k; v: T[k] } }[keyof T] export type KVPair = { k: PropertyKey; v: V } export type Objectify = { [k in T['k']]: Extract['v'] } export type OmitKV = T extends { v: V } ? never : T export type PickKV = T extends { v: V } ? T : never // https://www.totaltypescript.com/concepts/the-prettify-helper export type Prettify = { [K in keyof T]: T[K] } & {} export type PrettifyRec = { [K in keyof T]: PrettifyRec } & {} /** * Check source. * Maps over an object using `Object.entries` and returns a new object. */ export function objMapEntries< // Obj extends Record, ResultKey extends string, ResultValue, >( value: Obj, callback: (entry: [key: keyof Obj, value: Obj[keyof Obj]]) => readonly [ResultKey, ResultValue] ): Record { // @ts-expect-error We expect an error here return Object.fromEntries(Object.entries(value).map(callback)) }