I am currently utilizing an object to store a variety of potential colors, as seen below.
const cardColors = {
primaryGradientColor: "",
secondaryGradientColor: "",
titleTextColor: "",
borderColor: "",
categoryTextColor: "",
};
My goal is to update these properties individually using a function.
const updateColor = (colorType: typeof cardColors, color: string) => {
cardColors[colorType] = color;
}
However, I am encountering the following error:
Type '{ primaryGradientColor: string; secondaryGradientColor: string; titleTextColor: string; borderColor: string; categoryTextColor: string; }' cannot be used as an index type.
I intend to utilize the object as a reference for types in the function parameter, as demonstrated above.
I prefer not to create a separate type for this object since it would require updating in multiple places unnecessarily. Instead, I want to use this object for type verification purposes.
Furthermore, I am new to TypeScript.