Repository navigation
Pipe function + React.memo returns component with any props #38930
Copy link
Copy link
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Activity
RyanCavanaugh commented
on Jun 12, 2020 MemberMore actionsWhat's the definition of
memo?OliverJAsh commented
on Jun 12, 2020 ContributorAuthorMore actions- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Jun 15, 2020 RyanCavanaugh commented
on Jun 15, 2020 MemberMore actionsIf someone can provide an isolated repro we can investigate
dragomirtitian commented
on Jun 22, 2020 ContributorMore actionsRyan Cavanaugh (@RyanCavanaugh) Hope this helps:
// The presence of any overloads confuses inference, leave just one of them in and everything works declare function memo<T>(Component: T): T; declare function memo<T>(Component: T): T; declare function pipeWith<A, B>(a: A, ab: (a: A) => B): B; type Props = { foo: number }; declare const MyComponent: Props; // ✅ correct props type // Props const r1 = memo(MyComponent); // ❌ `unknown` props type // unknown const r2 = pipeWith(MyComponent, memo); // Workaround // ✅ correct props type // Props const r3 = pipeWith(MyComponent, (C) => memo(C));
Just the presence of any overloads will confuse the inference on the original use case. Leave just the one signature and everything works as expected.
Reacted by Oliver Joseph Ash- addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Dec 11, 2020 Ryan Cavanaugh (@RyanCavanaugh) here's a reproduction
3 remaining items
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
TypeScript Version: 3.9.2
Search Terms: generic pipe pipeWith react memo HOC props any
Code
Using latest version of
@types/react(at the time of writing: 16.9.35).Expected behavior:
See above.
Actual behavior:
See above.
Playground Link:
https://stackblitz.com/edit/react-ts-4ih6jn
Related Issues:
#25637, although that was closed as a duplicate of an issue which has since been closed (#10957), so I decided to post a new issue.