import { asMap } from "./asMap" type ExtractRecordValue = T extends Record ? V : never /** * Transforms a record object (with string keys and values of type V) * into a Map (getter). * * @template T - Type of the containing object * @template K - Type of the property key in T that will be transformed * * @param this - The object containing the property to transform * @param propName - The name of the property to transform into a Map * @returns A function that returns a Map backed by the key-value pairs from the record property */ export function objectToMapTransform< T extends { [k in K]?: Record | null | undefined }, K extends keyof T, >( propName: K ): (this: T) => Map> | Extract { return function (this: T): any { const record = this[propName] return record === null || record === undefined ? record : asMap(record) } }