I am currently attempting to generate a custom type based on a design token JSON file.
The JSON data is structured as follows:
{
"Black": {
"4": { "value": "#f6f6f6" },
"6": { "value": "#f2f2f2" },
"10": { "value": "#e8e8e8" },
"20": { "value": "#d3d3d3" },
"30": { "value": "#bcbcbc" },
"40": { "value": "#a7a7a7" },
"50": { "value": "#909090" },
"60": { "value": "#7b7b7b" },
"70": { "value": "#646464" },
"80": { "value": "#4e4e4e" },
"90": { "value": "#383838" },
"100": { "value": "#222222" }
},
"Blue": {
"4": { "value": "#F5F8F8" },
"8": { "value": "#EBF0F1" },
"10": { "value": "#E5EBED" },
"20": { "value": "#CCD9DC" },
"30": { "value": "#B2C5CA" },
"40": { "value": "#99B3B9" },
"50": { "value": "#7F9FA7" },
"60": { "value": "#668C96" },
"70": { "value": "#4C7984" },
"80": { "value": "#336673" },
"100": { "value": "#004050" }
},
"Teal": {
"20": { "value": "#ccfbf0" },
"40": { "value": "#99f8e1" },
"60": { "value": "#66f4d3" },
"80": { "value": "#33f1c4" },
"100": { "value": "#00edb5" }
}
}
Currently, I have created a union type for the colors using
type Color = keyof typeof colorJSON;
My next task is to establish another union type for all the nested keys within each color object that represent different tint levels like
type Tint = '4' | '6' | '8' etc...
. However, I'm struggling to recursively iterate through the colors and access these keys.
---Edit---
My goal is to ensure that the type automatically updates if new colors are added to the JSON file, so it needs to iterate through the structure rather than directly reference color names.