Inconsistent Flow errors when using object spread and intersections:
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Flow Try: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swBbAUwCcBzCgHgAUBGAGjEYCYA+ACgAdmALg5sw-TiK4BKKczAAyDpzABvVGE1UK+TFVKqAdMcHtjhiQF8A3Kkvp8AT34UwAZUZgAvGuwBDShEAZ3wqQmwaG1QnFzAAeU8fVT86EWxMMgAjaijUXBIQsCD+EQ9vXwCKEQByAAsKR2rc4GAwfFrCILAsPCISNrCKLvw4MD9MGkpsfDAaQgA3ClJ+Kjh+LoRCdqL+VBa22u1XNb7sLqDMXFwKCgATdkzMGZJXKD9CGCC91q2wBDhMDBbkUbmQDn4Zn4YDAwHAoAcKGCgrUAUCipdrnc8gVIRMpjMfEwRAk+BpxKt1lJFPFGKwyft2q84NDEOEaH84FQANZdTR8zT01orNZBKR02QcallLzcNSChHdZnwTYRDnc3n8zWa+X5M4zYXrADMVJ8BqCtk0+20un0anMZsNZmMxSiltajMVLJV7P+6q1Ard1r0pEotAoAgpQXYxWkFv9AbAQdtRhMkadhhdtma7o6XQoAA8AvwYK52gCaLUwLdETiqBCht9wTN2p0iijAcDsHAZtkxl6sfsguFrgqAfh+E9YfDxpMlvheNIwOEDp1UDP8bxVP5AmAACycdgpKpgQ3MSyxoA
```
/* @flow */
function merge(p1: P1, p2: P2): P1 & P2 {
return {...p1, ...p2};
}
type SP = {name: string};
type OP = {age: number};
const sp: SP = {name: 'hey'};
// this function tries to augment given props with sp
// three options succeed, but one fails
// it would seem that all of them should succeed
const augment = (
props: P & OP,
// the following works
// props: P,
): P & SP => {
// the following works
// const props3: P = props;
// return {...props3, ...sp};
// the following works
//return merge(props, sp);
// the following line generates type error
return {...props, ...sp};
};
// this example though demonstrates
// that this should not be allowed
// since the output of augment() in this case won't be P
// due to name being overwritten with different type
augment({name: 42, age: 31});
```
Contributor guide
Assessment
This issue has not been assessed yet.