Last active
July 9, 2016 21:49
-
-
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.
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
/* 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