Currently, I am in the process of developing a library with the following API structure:
export var reduce = <T, U>(
tArray: T[],
tReducer: (current: U, tItem: T, index: number, tArray: T[]) => U,
options: IChunkifyOptions = DEFAULT_OPTIONS,
memo?: U
): Promise<U>
In this implementation, similar to the standard JavaScript reduce method, the first item of tArray
is utilized as the default value for memo
if one is not provided.
if (memo === undefined) {
memo = tArray[0]; // Type 'T' is not assignable to Type 'U'
}
Attempting to cast (<U>
) results in the error message,
Neither Type 'T' nor Type 'U' is assignable to the other.
I am currently seeking feedback on how best to refine and define the API.