facebook / facebook/flow

Type check class that extends class from build in module

Aperta
#2,753 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
declarations
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.