facebook / facebook/flow

Using externally defined types for the arguments of generic classes causes strange ordering issues

Aperta
#2,455 6 commenti 0 reazioni 1 assegnatario Rivendicata da @avikchaudhuri Vedi su GitHub
bug Typing: unions/intersections
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

The following minimal test case demonstrates some strange ordering issues:

``` es6
/* @flow */

import type {X} from './test-module';

type Y = {name: 'Y'};

class Clazz {
method(func: () => t1 | t2) { // fix by flipping the order of `t1` and `t2` here
func();
}
}

const r: Clazz = new Clazz(); // or by flipping the order of `X` and `Y` here
r.method((): X => ({name: 'X'}));
r.method((): Y => ({name: 'Y'}));
```

where `test-module.js` is defined as:

``` es6
/* @flow */

export type X = {name: 'X'};
export type Y = {name: 'Y'};
```

This bug only happens when at least one of the types is defined in an external module. If both `X` and `Y` are defined externally then it still happens, but you need to flip the order to see the problem again.

Although this sounds like a real edge case bug, I'm actually unable to use the knowledge I've gleaned to work around the issue in my real code because there are quite a number of types coming from a number of external modules, and it would be a non-trivial task to determine which order I should specify the types in to fix the problem.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.