Currently, I am immersed in styled-system and attempting to define a pattern that is frequently employed within the library.
const space: { [key: string]: string } = [
'0.25rem',
'0.5rem',
'1rem',
'2rem',
'4rem',
'6rem',
];
space.xs = space[0];
space.sm = space[1];
space.md = space[2];
space.lg = space[3];
space.xl = space[4];
space.xxl = space[5];
An issue arises with the following error:
Type 'string[]' is not assignable to type '{ [key: string]: string; }'.
Index signature is missing in type 'string[]'.ts(2322)
I am uncertain about how to combine a number key and a string key for an Array index or how to merge the object and array. Although it functions as intended in vanilla javascript. The quick solution is to assign string
to any
, but my curiosity lies in understanding why this doesn't behave as anticipated. I would assume that an associative array pattern should be permissible.