In the scenario where I have a type similar to the one below and I aim to associate it with specific values during compile time, I can achieve this by:
type MyType = {
a: string;
b: string;
}
const MyMapping: { [k in keyof MyType]: number } = {
a: 3,
b: 2,
}
type X = typeof MyMapping['a'] // Output should be 3
Is there a method to apply the same concept to a combination of existing types?
type MyType = {
a: string;
b: string;
}
const MyMapping: /* Specialized type here */ = {
a: 3,
b: 2,
}
type X = typeof MyMapping['a'] // Expected result is 3
I understand that the approach presented above may not work as-is, but are there alternative formatting techniques to achieve this goal?