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.
This commit is contained in:
Wolfgang Faust
2017-10-04 12:09:50 -04:00
committed by Andy
parent 8835a0051e
commit e07dba0a0e
4 changed files with 53 additions and 0 deletions

12
types/object-map/index.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
// Type definitions for object-map 1.0
// Project: https://github.com/xixixao/object-map
// Definitions by: Wolfgang Faust <https://github.com/wolfgang42>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function objectMap<TInput, TOutput, TThis>(
target: {[k: string]: TInput},
callback: (this: TThis, currentValue: TInput, key: string, object: {[k: string]: TInput}) => TOutput,
thisArg?: TThis
): {[k: string]: TOutput};
export = objectMap;

View File

@@ -0,0 +1,18 @@
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);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"object-map-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{"extends": "dtslint/dt.json"}