I want to create a type where the object keys are the value from object values.
Example:
type AreaChartData = {
xAxis: string;
yAxis: string;
data: {
[Key in AreaChartData['xAxis'] | AreaChartData['yAxis']]: string | number;
}[];
};
In my example i want xAxis and yAxis as strings. But in the "data" attribute the values from xAxis and yAxis should be used as string literals so that i can force the user to have at least two keys with the names of the values.
Right now one way it works is to define two generics and use them later. But i hope that i can dynamically can convert the values to a type.
I'm using the newest typescript version.