Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed type issue with ComponentProps from older @types/react #1956

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ClassAttributes, ComponentClass, ComponentType } from 'react'
import {
ClassAttributes,
ComponentClass,
ComponentType,
FunctionComponent,
} from 'react'

import { Action, AnyAction, Dispatch } from 'redux'

Expand Down Expand Up @@ -82,7 +87,7 @@ export type GetLibraryManagedProps<C> = JSX.LibraryManagedAttributes<
export type ConnectedComponent<
C extends ComponentType<any>,
P
> = ComponentType<P> &
> = FunctionComponent<P> &
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComponentType is a union - your connect returns a function component so there was no need to use the ComponentType here. Somehow because of that union, the inferred props through ComponentProps were also computed as a union, and that caused a problem. This only occurred with older @types/react because their FunctionComponent included PropsWithChildren.

I've wanted to write a type test for this - but to pull it off you would have to extend your test suite with a @types/react matrix.

NonReactStatics<C> & {
WrappedComponent: C
}
Expand Down