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

Error reported on computed property key that was refined from union type to literal type #8306

Open
IsaacPacht opened this issue Feb 26, 2020 · 0 comments

Comments

@IsaacPacht
Copy link

Flow version: 0.119.0

Expected behavior

Given this code:

function f1(key: 'a' | 'b') {
  if (key === 'a') {
    const o = { [key]: 'x' };
  }
}

I would have expected no error. Even though flow doesn't allow union types for computed property keys, at the point where the error occurs, the type of "key" has already been refined to the literal type 'a'.

Actual behavior

I'm getting the error message:

Cannot use key [1] as a computed property. Computed properties may only be primitive literal values, but this one may be either string literal a [2] or string literal a [3]. Can you add a literal type annotation to key [1]? See https://flow.org/en/docs/types/literals/ for more information on literal types.

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

No branches or pull requests

1 participant