For example:
import { ArrayPrototypeReduce } from 'node-primordials'
const input: string[] = []
const result: Array<{ value: string }> = ArrayPrototypeReduce(
input,
(acc, value) => (acc.push({ value }), acc), [] as Array<{ value: string }>
)
The above code does not work because the type of ArrayPrototypeReduce is:
type ArrayPrototypeReduce = (
self: unknown,
callbackfn: (previousValue: unknown, currentValue: any, currentIndex: number, array: any[]) => unknown,
initialValue: unknown
) => unknown
It should be something like:
// note that there are improvements can be done to this type
type ArrayPrototypeReduce<T, I> = (
self: T[],
callbackfn: (previousValue: I, currentValue: T, currentIndex: number, array: T[]) => I,
initialValue: I
) => I
For example:
The above code does not work because the type of
ArrayPrototypeReduceis:It should be something like: