facebook / facebook/flow

Map over an object and using/retaining the type of its properties

Aperta
#3,140 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Here's the gist, I have an object that contains functions (selectors), that take a given object (let's call it X (the same for all these selectors) and map to a subpart of this object. I would like to iterate over this object, to create new functions that take an object containing X, and still returning the subpart of their subobject.

```javascript
type LocalState = {a: A}
type GlobalState = {g: LocalState};
// from
const sels = {
getA: (localState: LocalState): A => localState.a,
};

// to
const remappedSels = {
getA: (globalState: GlobalState): A => sels.getA(globalState.g),
};
```

I managed to keep the typings as long as I manually remap each function of sels, which is sadly not enough for me; I tried to have a look to the typings of ramda `mapObjIndexed`, but it's not precise enough. Using `Objet.keys(sel).reduce(...)` does not seem to work either, it loses the types. Does anyone have an idea on how to do so?

Here is the flowtry [example](https://flowtype.org/try/#0PTAEAEDMBsHsHcBQBjWA7AzgF1AczgEYCG0AylkVgKagC8oA3oqKEQFyPMugBuJAjBwDkRIQBouLPtA6QSGKhJYBfCcoDciFOmx4qWfnVAAKDAEo6APlAYAdNP6bUmHLn0A1EkdMXa1u9Ka2i6gcMgkpFTQVMhYsABOGIb0DG4GYnpYntAaWs66aaQArgTklFTJJuZWNrZEQSCgAGLxsAC2oADiNQCCrGgAJqB9fqAAGqBxXTVjwbrxVG1EAA5GADydGT0ZY5bGhSVl1Bzdoz1mHMbGI9Zjvtant-dcplEcN+MXJo+fVpJVJ3uNii+30xVKFGoPjMmm4cNAiAGMWgRAWoEgRTQsQAluhQEtlgB5AgAKwAkoMqAAPKgDNbbABCe0gaEu0neGQA1lQAJ4cbDxbFoXAZWAcYkkmJYIEM0UcBgAbW5fJsWEFwoAuu9lF9Fcr+WqhbgtaAGbl4dxEI0ABIISawUADB1YAAW2IwoGWqJwy1auHiRCWWGx4Wg0B5GQJyyNoDxrpozmoaBwsEgCMa+RwCyjtMi0EqBIlFKRNIGxmzK1BWHBRwqZgyYQiUSlCSSMLmWcWK2WuailSYLDSglAFeWVZrkLrxkbZGbsVb-FsQ-rXDS2Q4o-Hh0n-DM09gobzLcSi7XJBXuTyOhwGAN6twRlHPYGedP+n4+0IEUn7czoCo8StPEHBoEUbQEABj5dssz6vku76frAxBkD+TjXqABAcAQsCwNAUE5i+fbwVkJCIchtYwkAA)

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.