Is there a way to dynamically wrap each property in an interface with a generic type?
I have several interfaces defined in a library that I cannot modify by adding generics. One of the interfaces in the library is shown below as an example.
interface Original {
a: string;
b: number;
c: boolean;
}
I also created my own generic type for displaying values in the interface, such as SVG icons and units. Here is the generic interface I made:
interface GenericInterface<V> {
value: V;
units: string;
errorMsg?: string;
icons: ReactElement<any>;
}
My goal is to wrap each parameter in the Original
interface with the GenericInterface
, resulting in the modified interface below:
interface Modified {
a: GenericInterface<string>;
b: GenericInterface<number>;
c: GenericInterface<boolean>;
}
I've tried the following approach but it results in a union of all parameter types:
type ModifiedGeneric<T extends object, K extends keyof T> = Record<
K,
GenericInterface<T[K]>
>;
type Modified = ModifiedGeneric<
Original,
keyof Original
>;
This combines all parameter types into one which is not what I want. Is there a solution to achieve the desired output?