UNPKG

ut2

Version:

一个现代 JavaScript 实用工具库。[点击查看在线文档]。

21 lines (20 loc) 1.19 kB
import { ReduceArrayIterator, ReduceArrayLikeIterator, ReduceObjectIterator, ReduceStringIterator, WithNullable } from './types'; export interface Reduce { <T, R>(collection: WithNullable<T[]>, iteratee: ReduceArrayIterator<T, R>, initialValue: R): R; <R>(collection: WithNullable<string>, iteratee: ReduceStringIterator<R>, initialValue: R): R; <T, R>(collection: WithNullable<ArrayLike<T>>, iteratee: ReduceArrayLikeIterator<T, R>, initialValue: R): R; <T extends object, R>(collection: WithNullable<T>, iteratee: ReduceObjectIterator<T, R>, initialValue: R): R; <T>(collection: WithNullable<T[]>, iteratee?: ReduceArrayIterator<T, T>): T | undefined; (collection: WithNullable<string>, iteratee?: ReduceStringIterator<string>): string | undefined; <T>(collection: WithNullable<ArrayLike<T>>, iteratee?: ReduceArrayLikeIterator<T, T>): T | undefined; <T extends object>(collection: WithNullable<T>, iteratee?: ReduceObjectIterator<T, T[keyof T]>): T[keyof T] | undefined; } /** * 创建 reducer 函数 * * @private * @param dir 迭代方向 * @returns reduce 方法 */ declare function createReduce(dir: 1 | -1): Reduce; export default createReduce;