import type { DeepWritable } from 'ts-essentials'; /** Maps out the types of an object. */ type MergeIntersectingObjects = { [key in keyof ObjT]: ObjT[key] }; /** Generic - Converts the given Union type to an Intersection. */ type UnionToIntersection = // From https://stackoverflow.com/a/50375286 (UNION_T extends unknown ? (k: UNION_T) => void : never) extends (k: infer I) => void ? I : never; /** Removes all null/undefined values from an object. */ type CleanObject = { [P in keyof T]: Exclude; }; /** Type used for fromEntries to convert tuple array to an object. */ type EntriesType = Array<[PropertyKey, unknown]> | ReadonlyArray; /** Converts a tuple array into a Union type. */ type UnionObjectFromArrayOfPairs = DeepWritable extends Array< infer R > ? R extends [infer key, infer value] ? { [property in key & PropertyKey]: value } : never : never; /** Converts Array of tuple key/value pairs to a typed object. */ type EntriesToObject = MergeIntersectingObjects< UnionToIntersection> >; /** Standard object with unknown key/value types. */ type ObjectType = Record; export type { CleanObject, EntriesToObject, EntriesType, ObjectType };