I am in need of creating a new function that can modify an item in an array at a specified index using a given function.
const adjustItem = <T, U extends T[], V extends number>(index: V) =>
(f: (x: U[V]) => U[V]) => (originalArray: T[]) =>
Object.assign([], originalArray, { [index]: f(originalArray[index]) });
After implementing this function, I noticed that the return type is not as expected. Instead of U
, it returns:
never[] & T[] & {
[x: number]: U[V];
}
Any ideas on how to achieve a more useful return type?