facebook / facebook/flow

Intersection of intersections doesn't cast to itself after spreading

Open
#8,257 0 comments 0 reactions 0 assignees View on GitHub
bug Typing: unions/intersections
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Flow version: 0.155

## Expected behavior
`{...foo}` contains all the same properties as `foo` does, so it should cast to `FooBarBaz`

## Actual behavior
```
13: ({...foo}: FooBarBaz)
^ Cannot cast object literal to `FooBarBaz` because property `baz` is missing in object literal [1] but exists in `Baz` [2].
References:
13: ({...foo}: FooBarBaz)
^ [1]
9: type FooBarBaz = FooBar & Baz
```

* Link to Try-Flow or Github repo:
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgBiccYAvGAN5QkBcYAzhgE4CWAdgOYA0YAdAIC+mXAQBCAQ2bkqAIyn0mbLrwF9h2fGEkAvGZXk7FLDj35D0mgsTiTpFG2ABk2qZdFESd3TJt3nrjroACZ4AMYwUgQAblJgNHD0flK66AAUlGoJgkleKRI6AJSoYKVgQA

```js
/* @flow */

type Foo = {foo: string, ...}
type Bar = {bar: string, ...}
type Baz = {baz: string, ...}

type FooBar = Foo & Bar

type FooBarBaz = FooBar & Baz

declare var foo: FooBarBaz

({...foo}: FooBarBaz)
```

It works OK if I use a flat intersection `type FooBarBaz = Foo & Bar & Baz`

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.