Last active
September 11, 2017 10:48
-
-
Save nmn/b20a92e848c68d88f7fdb8353c71b1ca to your computer and use it in GitHub Desktop.
something like $Keys but for 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 | |
/* | |
This magic type will give you the union of the types of all the values in an object type. | |
This is still far from a fully dynamic $PropertyType, but it's a lot better than just using `any` | |
*/ | |
/* | |
Link: | |
https://flow.org/try/#0C4TwDgpgBAJA8gIwFYQMbADwDUB8UC8UA3gNQDaA1hCAFxQDOwATgJYB2A5gLp1YC+AKFCQoAfRhYAhgBsArhHrYANFDh14yNJlx5CWIeGgSZ8xWtWb0uscbkKMAKhVwcAt8OiIkBYgKhQSVDo2WQBbBAgmJT8AhDpGVk5o-xJJOgQAewzpCEk2aMEBABM0aUkmaAA3cqhaWCk7M2RXAG4ACjqE9g4oAB8oTOzctj6oEPDIgEo3AHoZ9rqAQSYmSRAMcYimHEmoOagAURWMpgYACwyAdxHUE4r0aRAoM8iIATmF4LCt0a7OXf2RyYJ3OVxudy0j2er3e8w6XwmTABM0Ox1O9Au1ygtxWkKeLwqsM+AyyOTyyNRwPRmPBuIe+JhH3hDGY3QpQJBGLB2Ih9OhhKAA | |
*/ | |
/* eslint-disable */ | |
type $Object<V> = {+[key: string]: V} | |
type _$Values<V, O: $Object<V>> = V | |
type $Values<O: Object> = _$Values<*, O> | |
type Obj = { | |
+c: number, | |
+b: boolean, | |
+a: string, | |
} | |
declare var y: $Values<Obj> | |
;(y: string | boolean | number) | |
;(y: Array<number>) // Error shown correctly here | |
;(y: number) // Error shown correctly here | |
;(y: number) // Error shown correctly here | |
;(y: boolean) // Error shown correctly here | |
;(y: string) // Error shown correctly here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment