Created
February 22, 2019 04:10
-
-
Save techieshark/d2811482567dbd2660464e3d5a41f8e4 to your computer and use it in GitHub Desktop.
Flow-typed version of Object.values()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
// Flow-typed version of Object.values() | |
// @see: problem - https://github.com/facebook/flow/issues/2221 | |
// @see: this solution - https://stackoverflow.com/a/51757027/1024811 | |
export default function objectValues<A, B>(obj: {[key: A]: B}): Array<B> { | |
return ((Object.values(obj): any): Array<B>); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import objectValues from './objectValues'; | |
test('objectValues() acts like Object.values()', () => { | |
const obj = { a: 1, b: 2 }; | |
expect(objectValues(obj)).toEqual(Object.values(obj)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment