facebook / facebook/flow

React.memo can't be used with intersection type props from v0.99

Open
#7,975 0 comments 0 reactions 0 assignees View on GitHub
bug needs triage react Typing: unions/intersections
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hi!

It won't work after updating flow to v0.104.0. It worked fine with flow < 0.99:

```js
// @flow
import React, { memo } from 'react';

type P1 = {
foo: string
}

type P2 = P1 & {
bar: string
}

type Props = P2 & {
baz: string
};

const Comp = (props: Props) => {
return

{props.foo} {props.bar} {props.baz}

};

const Memoized = memo(Comp)

export default Memoized
```

Flow version: v0.104.0

Repro code: https://flow.org/try/#0PTAEAEDMBsHsHcBQBLAtgB1gJwC6gEoCmAhgMY4A0oA3qKoarKAL6iRayqgDkWJ53ANyJEOAJ7pCoAAoBGUAF4aiUG1iwAXKADOOLMgB2Ac0TMR4yTIBMimfIBky1QCNiWLbv3HT5iVOkc6Nq20jaO1CqgrgBeHnqGJszCiKSwBrqgAMKc6LYAFOiB2loBsEEAlIoAfE6gfDgArlgGoAA8ACbIAG5V1IVl2gB0kOqsfUWDrlhj-UGTxNHMrcCdPabJqel4ALIMsMjRhO229IytpUFVedkY5SKEAB6YuKDthJDEDdA7ewdHQA

## Expected behavior

No errors

## Actual behavior

It throws:

```
20: const Memoized = memo(Comp)
^ Cannot call `memo` with `Comp` bound to `component` because property `baz` is missing in props [1] but exists in object type [2].
References:
20: const Memoized = memo(Comp)
^ [1]
12: type Props = P2 & { ^ [2]
```

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.