facebook / facebook/flow

Interface type within interface should be checked for "implements" instead as normal type while "implements" validation

Open
#7,539 0 comments 0 reactions 0 assignees View on GitHub
bug Typing: interfaces
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

In following fail example, `Foo` and `A` seem to be compared as subtype and supertype and cause it fail. But interface `B` is actually being fullfilled that you can totally operate `Bar#b` as an `A`.
Consider the [iterable and iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) case which an object got `[Symbol.iterator]` method that retrurns `iterator` should implements `iterable` , this kind of behavior should be resonable.

```js
interface A {
a: 'a'
}

interface B {
b: A
}

class Foo implements A {
a = 'a';
}

class Bar implements B {
b: Foo;
}
```

Flow version: 0.94.0

## Expected behavior

Interface types within interfaces should be treated and validated as interface implemantation but not as normal type while validating an "implements" check.

## Actual behavior

```
14: b: Foo
^ Cannot implement `B` [1] with `Bar` because `Foo` [2] is incompatible with `A` [3] in property `b`.
References:
13: class Bar implements B {
^ [1]
14: b: Foo
^ [2]
6: b: A
^ [3]
```

* Link to [Try-Flow](https://flow.org/try/#0JYOwLgpgTgZghgYwgAgILIN4ChnLgLmQHI4isBfLLUSWRFAIUx2QCNDUKqEAbOAZ37IAYgHtRyYAFsADjwhSI4Iemy44yALzFSAbi5ZeAoQzhRJs+YuXImatoTGiKQA)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.