type KeyedField = { key: TKey; }; type KeyValueMap = Partial>; /** * Filters keyed field descriptors to only those whose corresponding value in the given * values object is a non-empty string. * * This is useful for rendering or processing only the fields with actual, non-blank content, * e.g., when displaying optional sections in a UI or assembling objects with present values. * * @param values - An object mapping keys to string values (which may be empty, null, or undefined) * @param fields - Field descriptors with { key: TKey } * @returns An array of fields whose corresponding values[key] is a non-empty string */ export function filterFieldValues>( values: KeyValueMap, ...fields: TField[] ) { const filteredFields = fields.filter((field) => Boolean(values[field.key]?.trim())); return new Map(filteredFields.map((field) => [field.key, field] as const)); }