I have the following object:
interface Colors {
[key: string]: Colors | string
}
const colors: Colors = {
light: {
gray: '#aaa',
},
black: '#000',
}
The problem is that i need to check if the passed string value represents some color in colors object like that:
// input
const color = 'light-gray'
// what I already done to get the array of keys
const keys = color.split('-') // ['light', 'gray']
// how to check if `keys` are in `colors` object
// expected output: true
I already tried the following:
keys.every(key => key in colors) // key: light -> true, key: gray -> false
Basically I'm looking for something like this:
const lightGray = colors[...keys] // unfortunatelly won't work
Thanks in advance!