Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeScript: How to define a type with nested objects

$
0
0

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;};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>