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

Object type indexer subtyping of interface indexer is broken #5567

Open popham opened 6 years ago

popham commented 6 years ago

Okay code:

type O = {
  [string]: number
}

interface I {
  [string]: number
}

declare var o: O;
(o: I);

Fails with:

10: (o: I);
     ^ O. This type is incompatible with
10: (o: I);
        ^ I
    Indexable signature is incompatible:
        2:   [string]: number
                       ^ number. This type is incompatible with
        6:   [string]: number
              ^ string

The problem is that structural_subtype and its callers don't manage $key and/or $value when they're present in fields_pmap. That doesn't work with ObjT as it's currently modelled.

CrOrc commented 6 years ago

Reproduced in versions 0.37-0.69 https://flow.org/try/#0C4TwDgpgBA8lC8UDeAoKUDaBnYAnAlgHYDmAugFxSECuAtgEYS4oC+KKRwTAZgIYDG0AJLI0mHARIUqdRszYoAJhH4AbXrmgA3DVAD2lGAG4UACgNQhASiNA