facebook / facebook/flow

Error using union types in interface

Open
#4,084 3 comments 1 reaction 0 assignees View on GitHub
question Typing: interfaces Typing: property variance
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Minimal reproduction:
```js
// @flow
interface Foo {
type: string | string[];
}
function bar(): Foo {
return { type: 'hello' };
}
```
Expected behavior: Flow type-checks without issue.

Actual behavior: Error
```
test.js:3
3: type: string | string[];
^^^^^^^^ array type. This type is incompatible with the expected return type of
6: return { type: 'hello' };
^^^^^^^ string
```
Flow version: 0.47.0

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.