Incorrect constructor detected when using a Function in the left side of `extends`
- Ngôn ngữ chính
- Rust
- Star
- 22.3k
- Fork
- 1.9k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
```
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.