Say I have the following foldable interface:
export interface Foldable<F> {
reduce: <A>(fn: (b: A, a: A) => A, initial: A, foldable: F) => A;
}
And then I want to implement it for array:
export const getArrayFold = <A>(): Foldable<Array<A>> => {
return {
reduce: (fn, initial, array) => {
return array.reduce(fn, initial);
}
};
};
But the compiler complains with:
Argument of type '(b: A, a: A) => A' is not assignable to parameter of type '(previousValue: A, currentValue: A, currentIndex: number, array: A[]) => A'. Types of parameters 'a' and 'currentValue' are incompatible. Type 'A' is not assignable to type 'A'. Two different types with this name exist, but they are unrelated.
I don't understand how there are two different types of A
here.