class declaration with overloaded methods and the mixed type cause return type to be any
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Wasn't sure how to reproduce in the flow try because modules are used, but you can reproduce by modifying express's libdefs:
```js
// express libdef
import type { Server } from 'http';
declare class express$Application {
constructor(): void;
listen(port: number, hostname?: string, backlog?: number): void;
listen(path: string, callback?: (err?: ?Error) => mixed): void;
}
// @flow
import express from 'express'
const app = express()
app.listen
```
If you try to autocomplete on listen(), it will show a return type `any` with no signature, even though it's clearly a `Server`. Oddly enough if you change the `callback` function signature from `mixed` to `any`:
```js
// express libdef
import type { Server } from 'http';
declare class express$Application {
constructor(): void;
listen(port: number, hostname?: string, backlog?: number): void;
listen(path: string, callback?: (err?: ?Error) => any): void;
}
// @flow
import express from 'express'
const app = express()
app.listen
```
You'll see the function signatures again. I find this behavior quite confusing because if anything it should maybe show unknown, but any makes me think the type got coerced to `any`, even though it actually didn't.
Contributor guide
Assessment
This issue has not been assessed yet.