Flow version: v0.111 and up have this regression. v0.110 and lower work fine
Flow doesn't report an error.
Flow reports an error for the following code:
// @flow
const key: 'a' | 'b' = 'a';
const obj = {[key]: 42};
Error:
3: const obj = {[key]: 42};
^ Cannot use `key` [1] as a computed property. Computed properties may only be primitive literal values, but union type [2] is a union. Can you add a literal type annotation to `key` [1]? See https://flow.org/en/docs/types/literals/ for more information on literal types.
References:
2: const key: 'a' | 'b' = 'a';
^ [1]
2: const key: 'a' | 'b' = 'a';
^ [2]
This is deliberate as part of the changes described here: https://medium.com/flow-type/spreads-common-errors-fixes-9701012e9d58
Thanks for pointing me to this article. From reading the section on unions in computed properties, it sounds like this decision was made for performance considerations in a contrived scenario, and not because the code is actually faulty. Therefore, I'd disagree with the classification as "not a bug", since Flow is now complaining about valid code that was working prior to this change.
It's not a contrived scenario-- it makes Flow time out in our codebases.
I wonder who has 10k members sum types ...
Most helpful comment
Thanks for pointing me to this article. From reading the section on unions in computed properties, it sounds like this decision was made for performance considerations in a contrived scenario, and not because the code is actually faulty. Therefore, I'd disagree with the classification as "not a bug", since Flow is now complaining about valid code that was working prior to this change.