DefinitelyTyped/types/object-map/object-map-tests.ts
Wolfgang Faust e07dba0a0e Add type definitions for object-map. (#20114)
* Add type definitions for object-map.

* Rename object-map's type variables.

Per suggestion from @plantain-00

* object-map: Declare TThis type for thisArg.

Per suggestion from @andy-ms.
2017-10-04 09:09:50 -07:00

19 lines
312 B
TypeScript

import objectMap = require('object-map');
const obj = {foo: 7, bar: 3, baz: -1};
let total = 0;
const keys: string[] = [];
objectMap(obj, (val, key) => {
total += val;
keys.push(key);
});
const myThis = {
mul: 2,
count: 0,
};
objectMap(obj, function(val, key) {
this.count += this.mul * val;
}, myThis);