See this following code example:
type Properties = {
item0: { item0: string };
item1: { item1: string };
item2: { item2: string };
item3: { item3: string };
item4: { item4: string };
};
type Func<N extends keyof Properties> = ({}: Properties[N]) => number;
const Wrap = <N extends keyof Properties>(inner: Func<N>): Func<N> => {
return (v: Properties[N]) => inner(v) + 2;
};
type FuncSet = { [Property in keyof Properties]: Func<Property> };
const WrapSet = (inner: FuncSet): FuncSet => {
return {
item0: Wrap(inner.item0),
item1: Wrap(inner.item1),
item2: Wrap(inner.item2),
item3: Wrap(inner.item3),
item4: Wrap(inner.item4),
};
};
How would one refactor WrapSet such that it would iterate over the items in Properties so that they wouldn’t have to be explicitly specified?