I keep getting the below error from this line of code: oldUniforms[key] = tempUniforms[key];
. I don't understand why this doesn't work as I'm just creating a deep copy of an object of the same type.
Error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UpdatedUniformsType'.
No index signature with a parameter of type 'string' was found on type 'UpdatedUniformsType'.ts(7053)
Code:
type UpdatedUniformsType = {
u_BlockDia?: number;
u_CamPos?: [number, number];
};
const oldUniforms: UpdatedUniformsType = {
u_BlockDia: 16,
u_CamPos: [0, 0],
};
function setOldUniforms(updatedUniforms: UpdatedUniformsType) {
// Deep copy of updatedUniforms
const tempUniforms: UpdatedUniformsType = JSON.parse(JSON.stringify(updatedUniforms));
// Update oldUniforms using the deep copy
Object.keys(tempUniforms).forEach((key) => {
oldUniforms[key] = tempUniforms[key];
});
}