facebook / facebook/flow

Create a "Comparable" interface

Offen
#388 4 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
feature request
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

This code:

``` javascript
/** @flow */

class Foo {
val: T;

lessThan(other: Foo) {
return this.val < other.val; // XXX flow doesn't like this comparison
}
}
```

produces the following error:

```
baderror.js:3:15,20: number
This type is incompatible with
baderror.js:7:12,31: string

baderror.js:3:22,27: string
This type is incompatible with
baderror.js:7:12,31: number

Found 2 errors
```

In most type systems, the `T` in `other: Foo` would be the same `T` as for the current class. This would result in number↔number and string↔string comparisons, but never number↔string.

Removing the `` in `other: Foo` makes the error go away, but now I have no confidence that Flow is actually checking anything.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.