Definitions for array-foreach (#12536)

* Definitions for array-foreach

* update tsconfig as per PR

* update as per PR
This commit is contained in:
Steve 2016-11-13 09:26:51 +00:00 committed by Masahiro Wakame
parent 2c90c48e39
commit 727d0517ab
3 changed files with 79 additions and 0 deletions

View 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
View 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;

View 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"
]
}