Open ned opened 8 years ago
I've encountered a similar issue where an explicit type annotation on the value used as the key of a computed property also stops Flow from reporting incompatible values in the map.
/* @flow */
const key = 'key1';
const annotatedKey: string = 'key2';
const map: { [key: string]: string } = {
[key]: 1,
[annotatedKey]: 2
};
map[key] = 3;
map[annotatedKey] = 4;
Flow only reports errors for cases 1, 3 and 4, but all four cases should fail.
7: [key]: 1,
^ number. This type is incompatible with
6: const map: { [key: string]: string } = {
^ string
11: map[key] = 3;
^ number. This type is incompatible with
6: const map: { [key: string]: string } = {
^ string
12: map[annotatedKey] = 4;
^ number. This type is incompatible with
6: const map: { [key: string]: string } = {
^ string
Fixed for number keys in 80ca16f77ba81a3475dd1f7a9f4d9d9e3d71bca8 (all but example e
in initial example).
When using a map type, such as
{[key: string]: number}
, with an object literal that uses computed properties, Flow seems to be failing to detect that the types of the key or value of the object are not compatible with the map type.