Intersection of objects are not extendable with more properties or even queryable about other properties
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
```js
/* @flow */
function mergeOptions (defaultOptions: A, options: ?B): A & B {
return {...defaultOptions, ...options};
}
const obj = mergeOptions({a: 'abc'}, {b: 'dee'});
obj.c = 'cee';
```
Gives an error like: `^ assignment of property `c`. Property cannot be assigned on any member of intersection type`.
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swBbAUwCcBzCgeQAciSBnMAHgEEAuegIwBWFAgBowAIT5CR+AHwAKACYUoAQ0wx8TFtlY8wXcXGbE9BgPwSAlAa5gAZJLABvVGDBUK+TFVIuAOiCVdU1tUzZxIICTXVYAXwBuVHj0XDZ8MDghMABecmo6HTNWBRc1AwByNX5cSvjxF34qlQp662TUbMEA3DywStwKNsSgA
What's the reason for this?
You can't even check if another property is defined or not:
```js
/* @flow */
function mergeOptions (defaultOptions: A, options: ?B): A & B {
return {...defaultOptions, ...options};
}
const obj = mergeOptions({a: 'abc'}, {b: 'dee'});
if (obj.c !== undefined) {
console.log('c is defined');
}
```
Contributor guide
Assessment
This issue has not been assessed yet.