Imagine having a TypeScript interface like this:
interface IOriginal {
aaa: string;
bbb: boolean;
}
Now, let's say you want to create a similar interface with the same keys but different values (in this scenario, the values are generated using the Reducer generic from Redux, but let's keep it general):
import { Reducer } from "redux";
interface IDerived{
aaa: Reducer<string>;
bbb: Reducer<boolean>;
}
The question is: how can you generate IDerived
directly from IOriginal
without having to retype all the key-value pairs (avoiding repetition and needing to update in two places)? If these were objects, you could do something like this:
const derived = original;
for(var key in derived) derived[key] = Reducer(original[key]);
However, it's uncertain if there are equivalent tools for dealing with types/interfaces.