array-foreach: Add this type

This commit is contained in:
Andy Hanson 2016-12-19 13:39:30 -08:00
parent a4bd9fa3c1
commit 498fee439f
3 changed files with 9 additions and 7 deletions

View File

@ -17,21 +17,21 @@ arrayForEach(array, (i: number, index: number, array: Array<number>) => {
const resultThis: Array<{i: number, that: string}> = [];
arrayForEach(array, (i: number) => {
arrayForEach(array, function(i: number) {
resultThis.push({
i: i,
that: this.that
});
}, { that: 'jeff' });
arrayForEach(array, (i: number, index: number) => {
arrayForEach(array, function(i: number, index: number) {
resultThis.push({
i: i + index,
that: this.that
});
}, { that: 'jeff' });
arrayForEach(array, (i: number, index: number, array: Array<number>) => {
arrayForEach(array, function(i: number, index: number, array: Array<number>) {
resultThis.push({
i: array[i],
that: this.that

View File

@ -1,4 +1,4 @@
// Type definitions for array-foreach
// Type definitions for array-foreach 1.0
// Project: https://www.npmjs.com/package/array-foreach
// Definitions by: Steve Jenkins <https://github.com/skysteve>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@ -9,7 +9,8 @@
* @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;
declare function forEach<T>(arr: T[], callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => void): void;
declare function forEach<T, U>(arr: T[], callbackfn: (this: U, value: T, index: number, array: ReadonlyArray<T>) => void, thisArg: U): void;
/**
* Performs the specified action for each element in an array.
@ -17,5 +18,6 @@ declare function forEach<T>(arr: Array<T>, callbackfn: (value: T, index: number,
* @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;
declare function forEach<T extends Node>(arr: NodeListOf<T>, callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => void): void;
declare function forEach<T extends Node, U>(arr: NodeListOf<T>, callbackfn: (this: U, value: T, index: number, array: ReadonlyArray<T>) => void, thisArg: U): void;
export = forEach;

View File

@ -3,7 +3,7 @@
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": false,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [