У меня есть объект Javascript, например, так:
const childDict = {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
}
Я хочу динамически добавить его в другой родительский словарь в al oop, например:
let parentDict = {}
for(let i = 0 ; i < 3; i++){
parentDict["place" + i] = childDict
}
Итак в конце я получаю один из таких слов:
{
place0: {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
},
place1: {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
}
}
Однако, для l oop выдает ошибку компиляции:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.