I have this object type
interface MyObject<T> {
id: string
value: T
}
And this array type
type MyArray = MyObject[]
Now i need to declare a generic type that defines a new object based on id
s and value
s in the MyObject
's in the MyArray
. In my mind in should look something like this, but i am not sure what to put inside the {{}}
's.
interface MyArrayObject<MyArray> {
[id: {{MyArray[number].id}} ]: {{typeof MyArray[number].value}}
}
Example
const arr = [
{ id: "key1", value: 123 },
{ id: "key2", value: "abc" }
]
The resulting object contains all MyObject.id
s and their respective MyObject.value
.
const arrObject = {
"key1": 123
"key2": "abc"
}
Is it even possible to type this?