mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-04 19:42:46 +08:00
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:
12
types/object-map/index.d.ts
vendored
Normal file
12
types/object-map/index.d.ts
vendored
Normal 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;
|
||||
18
types/object-map/object-map-tests.ts
Normal file
18
types/object-map/object-map-tests.ts
Normal 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);
|
||||
22
types/object-map/tsconfig.json
Normal file
22
types/object-map/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/object-map/tslint.json
Normal file
1
types/object-map/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{"extends": "dtslint/dt.json"}
|
||||
Reference in New Issue
Block a user