Merge pull request #26716 from devCola/ramda-add-type-inference-for-mapObjIndexed

[ramda] add type inference for mapObjIndexed
This commit is contained in:
Nathan Shively-Sanders
2018-06-21 09:45:57 -07:00
committed by GitHub
2 changed files with 24 additions and 0 deletions

View File

@@ -1074,6 +1074,16 @@ declare namespace R {
/**
* Like mapObj, but but passes additional arguments to the predicate function.
*/
mapObjIndexed<T, TResult>(
fn: (value: T, key: string, obj?: {
[key: string]: T
}) => TResult,
obj: {
[key: string]: T
}
): {
[key: string]: TResult
};
mapObjIndexed<T, TResult>(fn: (value: T, key: string, obj?: any) => TResult, obj: any): { [index: string]: TResult };
mapObjIndexed<T, TResult>(fn: (value: T, key: string, obj?: any) => TResult): (obj: any) => { [index: string]: TResult };

View File

@@ -502,6 +502,20 @@ R.times(i, 5);
R.mapObjIndexed(prependKeyAndDouble, values); // => { x: 'x2', y: 'y4', z: 'z6' }
});
(() => {
const testObject: {
[key: string]: Error
} = {
hello: new Error('hello'),
};
const errorMessages = R.mapObjIndexed(
function test(value, key) {
// value should be inferred.
return value.message + String(key);
}, testObject);
console.log(errorMessages);
});
(() => {
const a: number[] = R.ap([R.multiply(2), R.add(3)], [1, 2, 3]); // => [2, 4, 6, 4, 5, 6]
const b: number[][] = R.of([1]); // => [[1]]