facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.09k stars 1.86k forks source link

indexer intersection regression #5698

Open jedwards1211 opened 6 years ago

jedwards1211 commented 6 years ago

For some reason I can't reproduce this in try flow; it only seems to be happening when I import the type declarations from one of my own packages.

The oppositeOf type below stopped working somewhere after Flow 0.56.0:

// @flow

export type Axis = 'x' | 'y'
export type Side = 'left' | 'right' | 'top' | 'bottom'
export type Direction = 'left' | 'right' | 'up' | 'down'
export type Dimension = 'width' | 'height'

declare export var axes: Array<Axis>
declare export var sides: Array<Side>
declare export var directions: Array<Direction>
declare export var dimensions: Array<Dimension>

declare export var sideInDirection: {[direction: Direction]: Side}
declare export var directionOf: {[side: Side]: Direction}
declare export var signumOf: {[what: Side | Direction]: number}
declare export var axisFor: {[what: Side | Direction | Dimension]: Axis}
declare export var dimensionFor: {[what: Side | Direction | Axis]: Dimension}
declare export var oppositeOf: 
  {[side: Side]: Side} & 
  {[direction: Direction]: Direction} & 
  {[dimension: Dimension]: Dimension} &
  {[axis: Axis]: Axis}
declare export var loSide: {[axis: Axis]: Side}
declare export var hiSide: {[axis: Axis]: Side}
declare export var negativeDirection: {[axis: Axis]: Direction}
declare export var positiveDirection: {[axis: Axis]: Direction}

Reproduction

New errors

Error: src/index.js:83
 83:     const oaxis = oppositeOf[axis]
                       ^^^^^^^^^^^^^^^^ string `x`. This type is incompatible with
 19:   {[side: Side]: Side} & 
               ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:19

Error: src/index.js:83
 83:     const oaxis = oppositeOf[axis]
                       ^^^^^^^^^^^^^^^^ string `y`. This type is incompatible with
 19:   {[side: Side]: Side} & 
               ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:19

Error: src/index.js:89
 89:     bounds[loSide[oaxis]] = -headWidth / 2
                ^^^^^^^^^^^^^ string `bottom`. This type is incompatible with
 23: declare export var loSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:23

Error: src/index.js:89
 89:     bounds[loSide[oaxis]] = -headWidth / 2
                ^^^^^^^^^^^^^ string `left`. This type is incompatible with
 23: declare export var loSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:23

Error: src/index.js:89
 89:     bounds[loSide[oaxis]] = -headWidth / 2
                ^^^^^^^^^^^^^ string `right`. This type is incompatible with
 23: declare export var loSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:23

Error: src/index.js:89
 89:     bounds[loSide[oaxis]] = -headWidth / 2
                ^^^^^^^^^^^^^ string `top`. This type is incompatible with
 23: declare export var loSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:23

Error: src/index.js:90
 90:     bounds[hiSide[oaxis]] = headWidth / 2
                ^^^^^^^^^^^^^ string `bottom`. This type is incompatible with
 24: declare export var hiSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:24

Error: src/index.js:90
 90:     bounds[hiSide[oaxis]] = headWidth / 2
                ^^^^^^^^^^^^^ string `left`. This type is incompatible with
 24: declare export var hiSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:24

Error: src/index.js:90
 90:     bounds[hiSide[oaxis]] = headWidth / 2
                ^^^^^^^^^^^^^ string `right`. This type is incompatible with
 24: declare export var hiSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:24

Error: src/index.js:90
 90:     bounds[hiSide[oaxis]] = headWidth / 2
                ^^^^^^^^^^^^^ string `top`. This type is incompatible with
 24: declare export var hiSide: {[axis: Axis]: Side}
                                        ^^^^ string enum. See: node_modules/isotrope/lib/index.js.flow:24

Found 10 errors
jedwards1211 commented 6 years ago

I tried using multiple indexers in one shape and got a "multiple indexers not supported", so I guess flow isn't necessarily intended to support an intersection of objects with indexers either?

declare export var oppositeOf: {
  [side: Side]: Side,
  [direction: Direction]: Direction,
  [dimension: Dimension]: Dimension,
  [axis: Axis]: Axis,
}