facebook / facebook/flow

Intersecting types based on Generic types

Open
#3,884 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

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]
})
})
}
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.