type Scales = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'
type TScale = { [k in Scales]: number }
type TSizing1 = { [k in Scales]?: string }
type TSizing2 = { [k in Scales]: string }
const scale: TScale = {
xxs: 1 / 8,
xs: 1 / 4,
s: 1 / 2,
m: 1,
l: 2,
xl: 4,
xxl: 8,
}
const sizing1: TSizing1 = {}
Object.entries(scale).forEach(([key, value]: [string, number]) => {
sizing1[key] = `${value * 1.6}rem`
})
const sizing2: TSizing2 = Object.assign(
{},
...Object.keys(scale).map(k => ({ [k]: `${scale[k] * 1.6}rem` })),
)
Both sizing1 and sizing2 will error because the lack of index signatures on TSizing1 and TScale respectively. But how am I supposed to add an index signature to a mapped type?