interfaces can no longer have constructors
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
The following worked as recently as 0.54.1, but does not work in 0.55 and later:
```
interface I {
constructor(): I;
}
class Impl implements I {
constructor() {}
}
```
[In 0.55](https://flow.org/try/#0JYOwLgpgTgZghgYwgAgJLIN4ChnIJAID2IAzmFAK4JiFQAUAlAFxoDcWAvllggDZwkSaALYAHXsmBjeEYRHBD02XAWJlK1Wo0xcuQA), the error is:
```
2: constructor(): I;
^ property `constructor` of I. Property not found in possibly undefined value
6: constructor() {}
^ undefined
```
[In 0.57.3](https://flow.org/try/#0JYOwLgpgTgZghgYwgAgJLIN4ChnIJAID2IAzmFAK4JiFQAUAlAFxoDcWAvllggDZwkSaALYAHXsmBjeEYRHBD02XAWJlK1Wo0xcuQA), the error is:
```
5: class Impl implements I {
^ Impl. This type is incompatible with
5: class Impl implements I {
^ I
Property `constructor` is incompatible:
6: constructor() {} ^ function. This type is incompatible with
2: constructor(): I;
^ function type
This parameter is incompatible:
6: constructor() {}
^ undefined. This type is incompatible with
2: constructor(): I;
^ I
Property `constructor` is incompatible:
2: constructor(): I;
^ property `constructor` of I. Property not found in possibly undefined value
6: constructor() {}
^ undefined
```
If I add `return this` to the `Impl` constructor body, flow accepts the code. It appears that flow forgot that the constructor is special, and the lack of an explicit return on all control flow paths does not mean that it can return `undefined`.
Contributor guide
Assessment
This issue has not been assessed yet.