import type { TouchedOf } from '../types/TouchedOf'; // Returns a `TouchedOf` instance where every field present in `values` is considered to have been touched. export const getEverythingTouchedOf = (values: T): TouchedOf => { if (Array.isArray(values)) { const touchedOf = {} as Record>; for (let index = 0; index < values.length; index++) { touchedOf[index.toString()] = getEverythingTouchedOf(values[index]) as TouchedOf; } return touchedOf as TouchedOf; } else if (typeof values === 'object') { const touchedOf = {} as Record>; for (const key of Object.keys(values)) { touchedOf[key] = getEverythingTouchedOf(values[key as keyof T]) as TouchedOf; } return touchedOf as TouchedOf; } else { // This must be a "simple" value (not an array or object), so just return `true` return true as TouchedOf; } };