I'm trying to define this object type.
colors: {
text: "#343D48", // body color and primary color
text_secondary: "#02073E", // secondary body color
heading: "#565F67", // primary heading color
heading_secondary: "#0F2137", // heading color
background: "#FFFFFF", // body background color
background_secondary: "#F9FBFD", // secondary background color
border_color: "#E5ECF4", // border color
primary: "#78F0AC", // primary button and link color
secondary: "#29CC5F", // secondary color - can be used for hover states
muted: "#7B8188", // muted color
dark: "#343D48",
accent: "#609", // a contrast color for emphasizing UI
yellow: "#F6C416",
error: "#F65241",
// highlight a background color for highlighting text
modes: {
dark: {
text: "#fff",
background: "#000",
primary: "#0cf",
secondary: "#09c",
muted: "#111",
},
},
},
This is what I wrote so far, I'm not sure how to define nested objects with TypeScript. How do I define the type for the code above? This is what I have so far:
export type Color = {
[colorName: string]: string;
};
[colorName: string]index signature becausemodesis not a color name, and will not have a string as its value. Are you sure you want that index signature rather than every property being explicitly typed? PLease describe your actual goal a bit here so we can give you better advice.typeof colorsto get the type of that object if you need it:type Colors = typeof colorsbut again, the right approach depends on what you want to do with this type.