Skip to content

Instantly share code, notes, and snippets.

@nmn nmn/$Values.ts
Last active Sep 11, 2017

Embed
What would you like to do?
something like $Keys but for values.
// @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
You can’t perform that action at this time.