Вот тип объекта, который я пытаюсь глубоко клонировать
Код: Выделить всё
fullValues: { [key : string ] : Array },
Код: Выделить всё
const facetValues: { [key: string ] : Array } = {};
// Type => facetedData?: FacetCollectionType
if (facetedData) {
Object.entries(facetedData).forEach(([key, value]) => {
Object.defineProperty(facetValues, key, { value: [] as string[]});
});
}
const [ facets, setFacets ] = useState(facetValues);
{facetedData &&
Object.keys(facetedData).length !== 0 ?
Object.entries(facetedData).map(([key, options]) => (
))
:
null
}
Код: Выделить всё
{
status: [],
plan: [],
}
Использование lodash deepclone
Код: Выделить всё
console.log(fullValues); // outputs { status: [], plan: [] }
console.log("after deep clone => ");
console.log(_cloneDeep(fullValues)); // outputs {}
Код: Выделить всё
console.log(fullValues); // outputs { status: [], plan: [] }
console.log("after deep clone => ");
console.log(JSON.parse(JSON.stringify(fullValues))); // outputs {}
Код: Выделить всё
let fullValues: { [key : string ] : Array } = { status: [], plan: [] };
console.log(fullValues); // outputs { status: [], plan: [] }
console.log("after deep clone => ");
console.log(_cloneDeep(fullValues)); // outputs { status: [], plan: [] }
Кажется, нет никакой логики в том, почему это происходит? Это бессмысленно!
Подробнее здесь: https://stackoverflow.com/questions/793 ... typescript