mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Definitions for array-foreach (#12536)
* Definitions for array-foreach * update tsconfig as per PR * update as per PR
This commit is contained in:
parent
2c90c48e39
commit
727d0517ab
39
array-foreach/array-foreach-tests.ts
Normal file
39
array-foreach/array-foreach-tests.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import arrayForEach = require('array-foreach');
|
||||
|
||||
const array: Array<number> = [1, 2, 3, 4];
|
||||
const result: Array<number> = [];
|
||||
|
||||
arrayForEach(array, (i: number) => {
|
||||
result.push(i);
|
||||
});
|
||||
|
||||
arrayForEach(array, (i: number, index: number) => {
|
||||
result.push(i + index);
|
||||
});
|
||||
|
||||
arrayForEach(array, (i: number, index: number, array: Array<number>) => {
|
||||
result.push(array[i]);
|
||||
});
|
||||
|
||||
const resultThis: Array<{i: number, that: string}> = [];
|
||||
|
||||
arrayForEach(array, (i: number) => {
|
||||
resultThis.push({
|
||||
i: i,
|
||||
that: this.that
|
||||
});
|
||||
}, { that: 'jeff' });
|
||||
|
||||
arrayForEach(array, (i: number, index: number) => {
|
||||
resultThis.push({
|
||||
i: i + index,
|
||||
that: this.that
|
||||
});
|
||||
}, { that: 'jeff' });
|
||||
|
||||
arrayForEach(array, (i: number, index: number, array: Array<number>) => {
|
||||
resultThis.push({
|
||||
i: array[i],
|
||||
that: this.that
|
||||
});
|
||||
}, { that: 'jeff' });
|
||||
21
array-foreach/index.d.ts
vendored
Normal file
21
array-foreach/index.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Type definitions for array-foreach
|
||||
// Project: https://www.npmjs.com/package/array-foreach
|
||||
// Definitions by: Steve Jenkins <https://github.com/skysteve>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Performs the specified action for each element in an array.
|
||||
* @param arr Array of items to iterate over
|
||||
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
declare function forEach<T>(arr: Array<T>, callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => void, thisArg?: any): void;
|
||||
|
||||
/**
|
||||
* Performs the specified action for each element in an array.
|
||||
* @param arr Nodelist of items to iterate over
|
||||
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
declare function forEach<T extends Node>(arr: NodeListOf<T>, callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => void, thisArg?: any): void;
|
||||
export = forEach;
|
||||
19
array-foreach/tsconfig.json
Normal file
19
array-foreach/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"array-foreach-tests.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user