Imagine having an imaginary api that provides color values based on user selections.
Consider the following arrays with string values:
const Colors1 = ['red', 'blue', 'purple'];
const Colors2 = ['blue', 'white'];
The api's responses are in the form of objects:
const ColorResponse1 = {
red: "#ff0000",
blue: "#0000ff",
purple: "#aa22ff"
}
const ColorResponse2 = {
blue: "#0000ff",
white: "#ffffff"
}
We could manually define the types as follows:
type TColorResponse1 = {
red: string;
blue: string;
purple: string;
}
type TColorResponse2 = {
blue: string;
white: string;
}
But is there a way to automatically generate these types based on the input arrays? Something like this:
type TGeneratedColors1 = {[any-color-from-Colors1: string]: string};
type TGeneratedColors2 = {[any-color-from-Colors2: string]: string};