I'm working in styled-system and am trying to type a pattern that is repeatedly used in that 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];
I'm getting this error:
Type 'string[]' is not assignable to type '{ [key: string]: string; }'.
Index signature is missing in type 'string[]'.ts(2322)
I'm not certain on how to reconcile a number key and a string key for an Array index or how to merge the object and array. It works as expected in vanilla javascript. The easy work around is setting string to any but I would like to know why this doesn't work as expected. I would think that an associative array pattern would be acceptable.