tap() function
此方法调用拦截器并返回一个值。拦截器使用一个参数调用。
Signature:
typescript
declare function tap<T, U>(
f: (arg: Awaited<T>) => U,
v: T,
): U extends Promise<any> ? Promise<Awaited<T>> : T;Example
ts
tap(console.log, [1, 2, 3, 4, 5]);
// log [1, 2, 3, 4, 5]
// return [1, 2, 3, 4, 5]
tap(async (a) => console.log(a), [1, 2, 3, 4, 5]);
// log [1, 2, 3, 4, 5]
// return Promise<[1, 2, 3, 4, 5]>