Skip to content

Instantly share code, notes, and snippets.

@nmn nmn/$Value.ts
Last active Jul 9, 2016

Embed
What would you like to do?
[BROKEN] Magic Flow Type Part 2: Trying to create a magic type $Value that gets the value type of an object and key.
/* eslint-disable */
// @flow
type $ObjectPair<K, V> = {[key: K]: V} | Object
type _$Value<Key: string, V, O: $ObjectPair<Key, V>> = V
type $Value<O: Object, K: $Keys<O>> = _$Value<K, *, O>
type Obj = {
c: number,
b: boolean,
a: string,
}
declare var y: $Value<Obj, 'b'>
;(y: string)
;(y: boolean) // Should Show an Error Here, But Doesn't
;(y: number) // Should Show an Error Here, But Doesn't
declare var x: $Value<Obj, 'a'>
;(x: number) // Correctly Shows an Error Here
;(x: boolean) // Correctly Shows an Error Here
;(x: string)
declare var z: $Value<Obj, 'c'>
;(z: string) // Should Show an Error Here, But Doesn't
;(z: boolean)
;(z: number) // Should Show an Error Here, But Doesn't
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.