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

fix: delete legacy type problems #1812

Merged
merged 1 commit into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 32 additions & 14 deletions src/components/connect.tsx
Expand Up @@ -280,19 +280,25 @@ function connect<
State = DefaultRootState
>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp, TOwnProps>
): InferableComponentEnhancerWithProps<
TStateProps & DispatchProp,
TOwnProps & ConnectProps
>

/* @public */
function connect<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps & ConnectProps>

/* @public */
function connect<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<ResolveThunks<TDispatchProps>, TOwnProps>
): InferableComponentEnhancerWithProps<
ResolveThunks<TDispatchProps>,
TOwnProps & ConnectProps
>

/* @public */
function connect<
Expand All @@ -303,7 +309,10 @@ function connect<
>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<
TStateProps & TDispatchProps,
TOwnProps & ConnectProps
>

/* @public */
function connect<
Expand All @@ -316,7 +325,7 @@ function connect<
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<
TStateProps & ResolveThunks<TDispatchProps>,
TOwnProps
TOwnProps & ConnectProps
>

/* @public */
Expand All @@ -329,7 +338,7 @@ function connect<
mapStateToProps: null | undefined,
mapDispatchToProps: null | undefined,
mergeProps: MergeProps<undefined, undefined, TOwnProps, TMergedProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps & ConnectProps>

/* @public */
function connect<
Expand All @@ -342,7 +351,7 @@ function connect<
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
mapDispatchToProps: null | undefined,
mergeProps: MergeProps<TStateProps, undefined, TOwnProps, TMergedProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps & ConnectProps>

/* @public */
function connect<
Expand All @@ -354,7 +363,7 @@ function connect<
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: MergeProps<undefined, TDispatchProps, TOwnProps, TMergedProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps & ConnectProps>

/* @public */
// @ts-ignore
Expand All @@ -368,23 +377,29 @@ function connect<
mapDispatchToProps: null | undefined,
mergeProps: null | undefined,
options: ConnectOptions<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<DispatchProp & TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<
DispatchProp & TStateProps,
TOwnProps & ConnectProps
>

/* @public */
function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: ConnectOptions<{}, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps & ConnectProps>

/* @public */
function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: ConnectOptions<{}, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<ResolveThunks<TDispatchProps>, TOwnProps>
): InferableComponentEnhancerWithProps<
ResolveThunks<TDispatchProps>,
TOwnProps & ConnectProps
>

/* @public */
function connect<
Expand All @@ -397,7 +412,10 @@ function connect<
mapDispatchToProps: MapDispatchToPropsNonObject<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: ConnectOptions<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>
): InferableComponentEnhancerWithProps<
TStateProps & TDispatchProps,
TOwnProps & ConnectProps
>

/* @public */
function connect<
Expand All @@ -412,7 +430,7 @@ function connect<
options: ConnectOptions<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<
TStateProps & ResolveThunks<TDispatchProps>,
TOwnProps
TOwnProps & ConnectProps
>

/* @public */
Expand All @@ -427,7 +445,7 @@ function connect<
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
options?: ConnectOptions<State, TStateProps, TOwnProps, TMergedProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps & ConnectProps>

/**
* Connects a React component to a Redux store.
Expand Down
22 changes: 8 additions & 14 deletions test/components/connect.spec.tsx
Expand Up @@ -2179,10 +2179,6 @@ describe('React', () => {
rtl.render(
<ProviderMock context={context} store={store1}>
<ProviderMock store={store2}>
{/*TODO: Since the connect type does not support this advanced usage,
we will ignore it for the time being and resolve it after merging connect and connectAdvanced
https://github.com/reduxjs/react-redux/pull/1781 */}
{/*// @ts-ignore */}
<Decorated context={context} />
</ProviderMock>
</ProviderMock>
Expand Down Expand Up @@ -2211,13 +2207,9 @@ describe('React', () => {
const Decorated = decorator(Container)

const store = createStore(() => expectedState)

rtl.render(
<ProviderMock store={store}>
{/*TODO: Since the connect type does not support this advanced usage,
we will ignore it for the time being and resolve it after merging connect and connectAdvanced
https://github.com/reduxjs/react-redux/pull/1781 */}
{/*// @ts-ignore */}
{/*@ts-expect-error*/}
<Decorated context={nonContext} />
</ProviderMock>
)
Expand Down Expand Up @@ -2259,6 +2251,7 @@ describe('React', () => {

const rendered = rtl.render(
<ProviderMock store={store}>
{/*@ts-expect-error*/}
<Decorated store={notActuallyAStore} />
</ProviderMock>
)
Expand Down Expand Up @@ -2307,7 +2300,6 @@ describe('React', () => {
</div>
)
}
const ConnectedComp2 = connect((state) => state)(Comp2)

type Comp1TStatePropsType = Store1State1Type
type Comp1NoDispatchType = NoDispatchType
Expand Down Expand Up @@ -2354,17 +2346,19 @@ describe('React', () => {
return state
}
}
const ConnectedComp2 = connect<
Store2State1Type,
unknown,
unknown,
Store2State1Type
>((state) => state)(Comp2)

const store1 = createStore(reducer1)
const store2 = createStore(reducer2)

const tester = rtl.render(
<ProviderMock store={store1}>
<ConnectedComp1>
{/*TODO: Since the connect type does not support this advanced usage,
we will ignore it for the time being and resolve it after merging connect and connectAdvanced
https://github.com/reduxjs/react-redux/pull/1781 */}
{/*// @ts-ignore */}
<ConnectedComp2 store={store2} />
</ConnectedComp1>
</ProviderMock>
Expand Down