mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 11:02:11 +08:00
Merge pull request #26716 from devCola/ramda-add-type-inference-for-mapObjIndexed
[ramda] add type inference for mapObjIndexed
This commit is contained in:
10
types/ramda/index.d.ts
vendored
10
types/ramda/index.d.ts
vendored
@@ -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 };
|
||||
|
||||
|
||||
@@ -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]]
|
||||
|
||||
Reference in New Issue
Block a user