facebook / facebook/flow

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

オープン
#4,331 コメント 0 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。