Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save klimashkin/7bbbea885f5b4a556512035934fdaa52 to your computer and use it in GitHub Desktop.
Save klimashkin/7bbbea885f5b4a556512035934fdaa52 to your computer and use it in GitHub Desktop.
Native implementation of Bluebird's Promise.props with flow annotation
function props<A, O: { [key: string]: A }>(promises: O): Promise<$ObjMap<O, typeof $await>> {
const objMapping: {[number]: string} = {};
return Promise
.all(Object.keys(promises).map((key: string, index: number) => {
objMapping[index] = key;
return promises[key];
}))
.then(fulfilledArray => {
return fulfilledArray.reduce((result, value, index: number) => {
result[objMapping[index]] = value;
return result;
}, {});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment