facebook / facebook/flow

Flow not checking `new C` when `C` is type `Class<...>`

Đang mở
#2,930 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Typing: destructors
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ả

I have this code and I would expect it to throw error; but it doesn't.

````javascript
type Foo = {
constructor(a: number): void;
};

function construct(FooClass: Class) {
const w = new FooClass('this is a string');
}
````

Similarly, this doesn't check errors

````javascript
type Foo = {
constructor(): void;
};

function construct(FooClass: Class>) {
const w: Foo = new FooClass();
}
````

I found no other way to say 'this variable is a class, you can call new() on it, only with the expected parameters, and it makes a new object of that type'. Maybe `Class` is not correct, but then what is; `$Type` and friends doesn't work either.

I am needing this, because I want to write at least somehow correct immutable-js Record typedefs; `var ABRecord = Record({a: 1, b: 2})` doesn't create a new record, but a new class, on which you can call `new ABRecord({})`. I want to capture that.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.