facebook / facebook/flow

Type check class that extends class from build in module

未關閉
#2,753 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
declarations
主要語言
Rust
星號
22.3k
分支
1.9k
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。