Skip to content

Instantly share code, notes, and snippets.

@nmn
Last active July 9, 2016 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmn/08242698c56590823a1e19bf0e686739 to your computer and use it in GitHub Desktop.
Save nmn/08242698c56590823a1e19bf0e686739 to your computer and use it in GitHub Desktop.
[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