From 7c2b73f0fc28d1b95efb3bfa263623771c3b9a13 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sun, 3 Oct 2021 13:17:06 -0400 Subject: [PATCH] Fix types issues with context props --- src/components/Provider.tsx | 2 +- src/components/connect.tsx | 6 +++--- test/components/connect.spec.tsx | 19 +++++++++---------- test/hooks/useDispatch.spec.tsx | 5 +++-- test/hooks/useSelector.spec.tsx | 5 +++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/components/Provider.tsx b/src/components/Provider.tsx index a85bb7fd6..8a95454c7 100644 --- a/src/components/Provider.tsx +++ b/src/components/Provider.tsx @@ -15,7 +15,7 @@ export interface ProviderProps { * If this is used, you'll need to customize `connect` by supplying the same context provided to the Provider. * Initial value doesn't matter, as it is overwritten with the internal state of Provider. */ - context?: Context + context?: Context children: ReactNode } diff --git a/src/components/connect.tsx b/src/components/connect.tsx index 9d2dc829e..7ef301529 100644 --- a/src/components/connect.tsx +++ b/src/components/connect.tsx @@ -425,9 +425,9 @@ function connect< TMergedProps = {}, State = DefaultRootState >( - mapStateToProps: MapStateToPropsParam, - mapDispatchToProps: MapDispatchToPropsParam, - mergeProps: MergeProps, + mapStateToProps?: MapStateToPropsParam, + mapDispatchToProps?: MapDispatchToPropsParam, + mergeProps?: MergeProps, options?: ConnectOptions ): InferableComponentEnhancerWithProps diff --git a/test/components/connect.spec.tsx b/test/components/connect.spec.tsx index 9de7d7725..6bad24a28 100644 --- a/test/components/connect.spec.tsx +++ b/test/components/connect.spec.tsx @@ -2154,10 +2154,9 @@ describe('React', () => { } } - const context = React.createContext | null>(null) + const context = React.createContext< + ReactReduxContextValue + >(null as any) let actualState @@ -2196,10 +2195,9 @@ describe('React', () => { } } - const context = React.createContext | null>(null) + const context = React.createContext< + ReactReduxContextValue + >(null as any) let actualState @@ -2451,8 +2449,9 @@ describe('React', () => { (state: RootStateType = 0, action: ActionType) => action.type === 'INC' ? state + 1 : state ) - const customContext = - React.createContext(null) + const customContext = React.createContext( + null as any + ) class A extends Component { render() { diff --git a/test/hooks/useDispatch.spec.tsx b/test/hooks/useDispatch.spec.tsx index 5fecddee8..d91343515 100644 --- a/test/hooks/useDispatch.spec.tsx +++ b/test/hooks/useDispatch.spec.tsx @@ -27,8 +27,9 @@ describe('React', () => { }) describe('createDispatchHook', () => { it("returns the correct store's dispatch function", () => { - const nestedContext = - React.createContext(null) + const nestedContext = React.createContext( + null as any + ) const useCustomDispatch = createDispatchHook(nestedContext) const { result } = renderHook(() => useDispatch(), { // eslint-disable-next-line react/prop-types diff --git a/test/hooks/useSelector.spec.tsx b/test/hooks/useSelector.spec.tsx index 4a2d851ce..6c8402ea1 100644 --- a/test/hooks/useSelector.spec.tsx +++ b/test/hooks/useSelector.spec.tsx @@ -697,8 +697,9 @@ describe('React', () => { }) it('subscribes to the correct store', () => { - const nestedContext = - React.createContext(null) + const nestedContext = React.createContext( + null as any + ) const useCustomSelector = createSelectorHook(nestedContext) let defaultCount = null let customCount = null