Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$Values not working properly #4411

Closed
andykais opened this issue Jul 18, 2017 · 3 comments
Closed

$Values not working properly #4411

andykais opened this issue Jul 18, 2017 · 3 comments

Comments

@andykais
Copy link

Going over changelog for 0.50.0, $Values is implemented. However, both on my local machine (flow version reports 0.50.0) and on master on flow.org/try $Values does not report errors when a variable typed with $Values of an object do not match any of them

@vkurchatkin
Copy link
Contributor

In your example CHANGE_LOCATION has type string, so everything works as expected. See: #2639

@andykais
Copy link
Author

I guess I misunderstood the purpose of $Values, is its expected behaviour not as described in this issue?

@seveibar
Copy link

Values doesn't seem to be the issue here, if you change your example from...

/* @flow */

const CHANGE_LOCATION = 'app/page/CHANGE_LOCATION'
const valueHolder = { CHANGE_LOCATION }
type TYPE_CHANGE_LOCATION = $Values<typeof valueHolder>

const x: TYPE_CHANGE_LOCATION = 'x'

to

/* @flow */

const CHANGE_LOCATION:'app/page/CHANGE_LOCATION' = 'app/page/CHANGE_LOCATION'
const valueHolder = { CHANGE_LOCATION }
type TYPE_CHANGE_LOCATION = $Values<typeof valueHolder>

const x: TYPE_CHANGE_LOCATION = 'x'

You'll get the expected error,

7: const x: TYPE_CHANGE_LOCATION = 'x'                                   ^ string. Expected string literal `app/page/CHANGE_LOCATION`, got `x` instead
7: const x: TYPE_CHANGE_LOCATION = 'x'
            ^ string literal `app/page/CHANGE_LOCATION`

The real question here is: Should flow be making the string literal assignment the type of the string (if I've phrased that correctly)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants