facebook / facebook/flow

Intersection of objects are not extendable with more properties or even queryable about other properties

Aperta
#5,142 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

```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');
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.