facebook / facebook/flow

Broken Autocomplete — Module Definitions: Polymorphic Type Aliases

Open
#4,588 2 comments 1 reaction 0 assignees View on GitHub
autocomplete
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**TL;DR:** If an export is an object and a value has a type which is polymorphic, type inference breaks ☹️
___
Took me a while to figure out why [my flow-typed library](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/styled-components_v2.x.x/flow_v0.42.x-/styled-components_v2.x.x.js) was not providing autocomplete and type-a-head results & I finally narrowed it down to polymorphic type aliases...

It seems to apply to all library type export definitions (possibly more), flow-typed or not.
___
```js
// ./flowtype-definitions/
declare module 'foo-module' {
declare type Bar = { quux: 'quux' }
declare type Baz = { quuux: 'quuux' }

declare module.exports: {
bar: Bar,
baz: Baz,
}
}
```
```js
// ./foo.js
import foo from 'foo-module'

foo.ba // (See attached screenshots)
```
___
_So far so good, we see both results..._

screen shot 2017-08-12 at 8 36 30 pm

_Huh...no autocomplete or type for bar?_

screen shot 2017-08-12 at 8 36 48 pm

_But ``baz`` works!_

screen shot 2017-08-12 at 8 37 13 pm

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.