#Convert type of array of objects to an object type

1 messages · Page 1 of 1 (latest)

cursive fractal
#

This is the following format:

readonly [{
    readonly fieldName: "index";
    readonly type: "number";
    readonly getterType: "row_index";
}, {
    readonly fieldName: "lol";
    readonly type: "number";
    readonly getterType: "row_index";
}]

I want to convert a type like this into the following type:

{
  index: "number",
  lol: "number"
}

The key is the fieldName and the value is the type. I don't want a Record because the type can differ and each of these key & values need to be required. I've tried using mapped types but it won't work because the type I want to convert has an array. Indexing it with type[number] would just create a union and I don't want a union.
As a note, it doesn't matter whether it's readonly or not. Thanks for the help

#

Nevermind I just got copilot X to solve it for me 😭

#

I can't believe it actually worked its literally crazy