The problem with the last attempt was that Record seemed to expect only string | number | symbol, and since TypeScript unsure what T[U] gonna be, hence it threw the error. I found that we can tell TS a little bit more about T as below

const convertListToMap = <
  T extends { [key: string|number]: string | number },
  U extends keyof T,
  V extends keyof T
>(
  list: T[],
  key: U,
  secondKey: V
) => {
  const map = {} as Record<T[U], T[V]>;
  for (const ele of list) {
    map[ele[key]] = ele[secondKey];
  }
  return map;
};

From the above, we are telling typescript that T is gonna be an object with key of string, and the value is gonna be of type string | number, with that, TypeScript is happy with the definition Record<T[U], T[V]>

This solution works great and TS can infer correctly

const personObj = convertListToMap([{name: 'isaac', age: 17}, {name: 'john', age: 20}], 'name', 'age')
// const personObj: Record<string, number>

const languageObj = convertListToMap([{race: 'chinese', language: 'mandarin'}, {race: 'malay', language: 'melayu'}], 'race', 'language')
// const languageObj: Record<string,string>
Answer from Isaac on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-convert-an-array-of-objects-into-object-in-typescript
How to Convert an Array of Objects into Object in TypeScript ? - GeeksforGeeks
July 23, 2025 - ... The Object.assign() method ... object. ... Example: The below code uses object.assign() method with rest parameter to convert an array of objects into a single object....
🌐
Medium
kasama-chenkaow.medium.com › typescript-convert-array-of-object-to-object-with-id-as-a-key-81d012ca70c5
Typescript: Convert an array of objects to object with ID as a key and correct typing | by Kasama Chenkaow | Medium
September 1, 2023 - K : never; }[keyof T]; const arrayToKeyObject = <T extends Record<StringKeys<T>, string | number | symbol>, TKeyName extends keyof Record<StringKeys<T>, string | number | symbol>>(array: T[], key: TKeyName): Record<T[TKeyName], T> => Object.fromEntries(array.map(a => [a[key], a])) as Record<T[TKeyName], T> playground · Typescript ·
Discussions

How to convert array to object in TypeScript?
14 Typescript convert array to object with specified type More on stackoverflow.com
🌐 stackoverflow.com
September 28, 2021
Typescript convert array to object with specified type - Stack Overflow
I'm trying to convert an array of classes to a object that has it's class name as the object key. So; I have an array of classes: const renderers = [ Battery, Kind ] And I want to convert... More on stackoverflow.com
🌐 stackoverflow.com
Typescript: Is there a simple way to convert an array of objects of one type to another - Stack Overflow
I have an array of Item that needs to be converted into an array of ViewItem. More on stackoverflow.com
🌐 stackoverflow.com
Typescript convert object to Array - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
January 16, 2018
🌐
Themuuj
themuuj.com › blog › 2021 › 04 › typescript-array-to-object
TypeScript Convert Array to Object • themuuj.com
May 4, 2021 - // example data structured as an ... '\uD83D\uDCA6' } ]; // convert to lookup object using the `name` property const lookup = arrayToObject(items, i => i.name); for(const element of ['earth', 'wind', 'fire', 'water']) { const item ...
🌐
DEV Community
dev.to › afewminutesofcode › how-to-convert-an-array-into-an-object-in-javascript-25a4
Javascript Array to Object: How to convert an array into an object in javascript - DEV Community
December 31, 2022 - May be unnecessary in future TypeScript versions. • works perfectly for variable data, but only almost perfect for constant data. Here in this example if you denote that test array as const, TS will be able to tell you that the object has 5 properties 111, 112, 122, 123, 125, but won't be able to tell you which object exactly under each key and think its a union type of all objects for each key.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-array-to-object
Converting TypeScript Array to Object: A Comprehensive Guide
In this guide, we will explore different methods to convert TypeScript arrays to objects. One common approach to convert an array to an object is by using the reduce() method. This method allows you to iterate over the array and build an object based on the elements' keys and values.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-array-to-array-of-objects
Converting TypeScript Arrays to Array of Objects: A Comprehensive Guide
For more complex transformations, ... arrayOfPeople = convertArrayToObjects(names); In this example, the convertArrayToObjects function converts an array of names into an array of Person objects with an id and name....
Find elsewhere
🌐
Webdevtutor
webdevtutor.net › blog › typescript-type-array-to-object
Converting TypeScript Type Array to Object: A Step-by-Step Guide
For example, you can use the lodash library: import { mapValues } from 'lodash'; type Colors = ['Red', 'Green', 'Blue']; const colorsObject = mapValues(Colors, () => null); console.log(colorsObject); // Output: { "Red": null, "Green": null, "Blue": null } ... Converting a TypeScript type array ...
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-convert-object-to-array
How to Convert an Object to an Array in TypeScript | bobbyhadz
February 27, 2024 - Here is an example of how array destructuring works. ... Copied!const arr = ['bobby', 'hadz']; const [a, b] = arr; console.log(a); // 👉️ "bobby" console.log(b); // 👉️ "hadz" We're basically unpacking the array's elements into variables. Note that the order is preserved. I've also written an article on how to convert an object to a JSON string.
🌐
Sling Academy
slingacademy.com › article › typescript-convert-object-array-vice-versa
TypeScript: How to Convert Object to Array and Vice-Versa - Sling Academy
A good day’s work it’s been, converting objects to arrays, and arrays to objects—akin to turning lead into gold. The spells and prayers outlined herein will serve you mightily as you stride confidently through the TypeScript wilderness, artfully transmuting data structures as the task at hand requires.
🌐
Medium
medium.com › chrisburgin › javascript-converting-an-object-to-an-array-94b030a1604c
Javascript, Converting an Object to an Array of Objects. | by Chris Burgin | Spark | Medium
December 16, 2017 - Javascript, Converting an Object to an Array of Objects. A while back I wrote an article that got some traction about converting an Array of Objects to an Object. Today we are going to do the …
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-array-to-object
Convert an Array to an Object using JavaScript | bobbyhadz
Which approach you should pick depends on whether you need to use the array's indexes as object keys or you need to use custom keys. Use the Object.assign() method to convert an array to an object.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-from-array-to-object
Converting Arrays to Objects in Typescript
Converting arrays to objects is a common task in Typescript development. By using the methods outlined in this post, you can efficiently transform your data structures to suit your application's needs.
🌐
Attacomsian
attacomsian.com › blog › javascript-convert-array-to-object
How to convert an array to an object in JavaScript
November 6, 2022 - Using the Object.fromEntries() method to convert an array of key-value pairs to an object, e.g. const obj = Object.fromEntries(arr). The Object.assign() method was introduced in ES6, and it copies the values of all enumerable own properties ...
🌐
Medium
medium.com › @kin32yc › a-typesafe-way-to-transform-array-to-object-in-javascript-0f04a96b2b85
A Type-Safe Approach to Transforming an Array into an Object in JavaScript | by Kinsey.C | Medium
August 30, 2024 - Object.assign is used to take multiple objects as input and merge them into the first object, effectively combining their properties. On the other hand, Array.map is a function that transforms each item in the array. By converting each item into an object with the id as the key, these transformed objects can then be merged into a single object using Object.assign.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-an-object-into-array-of-objects-in-javascript
How to Convert an Object into Array of Objects in JavaScript? | GeeksforGeeks
January 23, 2025 - Converting an array of objects into a single object is a common task in JavaScript and TypeScript programming, especially when you want to restructure data for easier access.