facebook / facebook/flow

Incorrect constructor detected when using a Function in the left side of `extends`

未关闭
#4,331 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
22.3k
派生
1.9k
PR 合并指标
30 天内没有已合并 PR

描述

When a function call is used as the left side of an class extends expression, Flow does not correctly detect the constructor based on the function result. Here is an example that demonstrates the problem:

```javascript
//@flow

class OneArgClass {
/*::
argA: string
*/
constructor (argA) {
this.argA = argA;
}
}

class TwoArgClass {
/*::
argB: string
argC: string
*/
constructor (argB, argC) {
this.argB = argB;
this.argC = argC;
}
}

const FunctionMixin = (Base) => class extends Base {

notInteresting () {
console.log('Do nothing');
}
};

class OneArgSubclass extends FunctionMixin(OneArgClass) {

}

class TwoArgSubclass extends FunctionMixin(TwoArgClass) {

}

const oneArgInstance = new OneArgSubclass('argA');
const twoArgInstance = new TwoArgSubclass('argB', 'argC');
```

When that code is checked by flow, the following error is shown:

```
index.js:38
38: const oneArgInstance = new OneArgSubclass('argA');
^^^^^^^^^^^^^^^^^^^^^^^^^^ constructor call
19: this.argC = argC;
^^^^ undefined (too few arguments, expected default/rest parameters). This type is incompatible with
19: this.argC = argC;
^^^^^^^^^ string

index.js:39
39: const twoArgInstance = new TwoArgSubclass('argB', 'argC');
^^^^^^ unused function argument
v-------------------
7: constructor (argA) {
8: this.argA = argA;
9: }
^ function expects no more than 1 argument

Found 2 errors
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。