record.ts 263 B

123456789
  1. export const tupleToRecord = <
  2. KeyType extends string | number | symbol,
  3. ValueType
  4. >(
  5. tuples: [KeyType, ValueType][]
  6. ): Record<KeyType, ValueType> =>
  7. tuples.length > 0
  8. ? (Object.assign as any)(...tuples.map(([key, val]) => ({ [key]: val })))
  9. : {}