Dynamic index signature parameter type

How can I create a dynamic index signature parameter type that doesn't require all of the keys from the mapped type?
enum Color {
cyan = 'cyan',
white = 'white',
gray = 'gray',
}

type Variants = {
[style: string]: {[key in Color]: string}
}

const foo: Variants = {
solid: {
gray: '...'
}
}
//error: Type '{ gray: string; }' is missing the following properties from type '{ cyan: string; white: string; gray: string; }': cyan, white
enum Color {
cyan = 'cyan',
white = 'white',
gray = 'gray',
}

type Variants = {
[style: string]: {[key in Color]: string}
}

const foo: Variants = {
solid: {
gray: '...'
}
}
//error: Type '{ gray: string; }' is missing the following properties from type '{ cyan: string; white: string; gray: string; }': cyan, white
1 Reply
PoppingPopper
PoppingPopperOP3y ago
lmaooo thank you!

Did you find this page helpful?