facebook / facebook/flow

Type check class that extends class from build in module

Đang mở
#2,753 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
declarations
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 was creating file definition for one of the modules and noticed that when I try to use a build in class type type checking stops to work.

`flow-typed/npm/restify.js`
```js
// @flow
import http from 'http';

declare module restify {
declare class MyClass extends http.Server {
this_exists_so_its_fine(): *;
}

declare function createServer(): MyClass;
}
```

`server.js`
```js
// @flow

import {
createServer,
MyClass,
} from 'restify';

export default function start(): void {
const s: MyClass = createServer();

s.this_exists_so_its_fine();
s.this_does_not_exist(); //This line is passing too!!
}
```
The full example is at: [https://github.com/pitrew/flow-type-error](https://github.com/pitrew/flow-type-error)

What I've found is that there are some classes copypased from modules and renamed with $ sign to be accesible (like: `net$Server` or `events$EventEmitter`). But http$Server is not copied so cannot be used that way.

There is one issue #2102 that was originally describing the same problem but with EventEmmiter. The answer by @avikchaudhuri at that time (Jul 20) was:
> Are you saying that the above code typechecks differently when you use EventEmitter after import vs. the global (but intended to be private to the lib file) events$EventEmitter? I don't think we support importing from one lib file to define another yet. So it's kind of expected.
>
> But this is also kind of a missing feature...

And there is a comment in flow source code about this at [https://github.com/facebook/flow/blob/v0.33.0/lib/node.js#L576](https://github.com/facebook/flow/blob/v0.33.0/lib/node.js#L576):
```js
// TODO: This is copypasta of the EventEmitter class signature exported from the
// `events` module. The only reason this exists is because other module
// interface definitions need to reference this type structure -- but
// referencing type structures defined in other modules isn't possible at
// the time of this writing.
declare class events$EventEmitter {
```

#### Q1: Is there any chance to add this *missing feature*?
#### Q2: How can I create a definition of my module using build in `http.Server` type and still have type checking wokring

Thanks

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.