mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Merge pull request #23517 from thorn0/angular-foreach-array-likes
AngularJS: improve types for `foreach` (support for array-likes)
This commit is contained in:
@@ -710,6 +710,24 @@ function test_angular_forEach() {
|
||||
this.push(`${key}: ${value}`);
|
||||
}, log);
|
||||
// expect(log).toEqual(['name: misko', 'gender: male']);
|
||||
// $ExpectType NodeListOf<HTMLImageElement>
|
||||
angular.forEach(document.getElementsByTagName('img'), (value, key, obj) => {
|
||||
value; // $ExpectType HTMLImageElement
|
||||
key; // $ExpectType number
|
||||
obj; // $ExpectType NodeListOf<HTMLImageElement>
|
||||
});
|
||||
// $ExpectType number[]
|
||||
angular.forEach([1, 2, 3], (value, key, obj) => {
|
||||
value; // $ExpectType number
|
||||
key; // $ExpectType number
|
||||
obj; // $ExpectType number[]
|
||||
});
|
||||
// $ExpectType string
|
||||
angular.forEach('123', (value, key, obj) => {
|
||||
value; // $ExpectType string
|
||||
key; // $ExpectType number
|
||||
obj; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
// angular.element() tests
|
||||
|
||||
Vendored
+5
-1
@@ -100,7 +100,11 @@ declare namespace angular {
|
||||
* @param iterator Iterator function.
|
||||
* @param context Object to become context (this) for the iterator function.
|
||||
*/
|
||||
forEach<T>(obj: T[], iterator: (value: T, key: number, obj: T[]) => void, context?: any): T[];
|
||||
forEach<T, U extends ArrayLike<T> = T[]>(
|
||||
obj: U,
|
||||
iterator: (value: U[number], key: number, obj: U) => void,
|
||||
context?: any
|
||||
): U;
|
||||
/**
|
||||
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user