facebook / facebook/flow

Intersecting types based on Generic types

Offen
#3,884 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Lets say I have an object type that represents the template of other more specific types. How does one define the more specific type so that the following usecase does not fail?

Here's a failing attempt:

```js
type Data = {
loading: boolean,
error: string,
fetch: (options: {
update: (prevResult: T1, moreData: { moreResult: T1, moreVar: Object }) => Object
}) => void
}

type SpecificData = Data & {
items: Array
}

const f = (data: SpecificData) => ({
data,
loadMore: () => {
data.fetch({
update: (prevResult, { moreResult, moreVar }) => ({
items: [...prevResult.items, ...moreResult.items]
})
})
}
})
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.