UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

35 lines (34 loc) 1.13 kB
import { type ArrayElement, type TupleIndexesRecursive } from '@augment-vir/core'; import { type Writable } from '../type/writable.js'; /** * Performs * [`[].map()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map) * on an array but transfers the input tuple's size to the output type. * * @category Array * @category Package : @augment-vir/common * @example * * ```ts * import {typedMap} from '@augment-vir/common'; * * const result = await typedMap( * [ * 1, * 2, * 3, * 4, * 5, * ], * (value) => { * return value + 1; * }, * ); * ``` * * @returns A new array (does not mutate). * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function typedMap<const ArrayGeneric extends ReadonlyArray<any>, const OutputType>(arrayToMap: ArrayGeneric, mapCallback: (value: ArrayElement<NoInfer<ArrayGeneric>>, index: TupleIndexesRecursive<ArrayGeneric>, array: NoInfer<ArrayGeneric>) => OutputType): Writable<{ [Index in keyof ArrayGeneric]: OutputType; }>;