From b50f392fd1dcca07720e99c2be5c6294da859ab7 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 6 Oct 2022 14:19:25 +0100 Subject: [PATCH 1/3] `Provider`: pass state (`S`) generic through to `ProviderProps` This is necessary to catch mistakes such as this, where the type of `serverState` does not match the type of the state in the provided `store`. ```tsx import { Provider } from 'react-redux'; import { Store } from 'redux'; declare const store: Store<{ foo: string }>; foo ``` --- src/components/Provider.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Provider.tsx b/src/components/Provider.tsx index 364ff7bc8..e3340355d 100644 --- a/src/components/Provider.tsx +++ b/src/components/Provider.tsx @@ -24,12 +24,12 @@ export interface ProviderProps { children: ReactNode } -function Provider({ +function Provider({ store, context, children, serverState, -}: ProviderProps) { +}: ProviderProps) { const contextValue = useMemo(() => { const subscription = createSubscription(store) return { From e7017ed983dc99876192fd0b6e0ca6e063d9f651 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 6 Oct 2022 16:33:09 +0100 Subject: [PATCH 2/3] Add type test --- test/typetests/provider.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/typetests/provider.tsx diff --git a/test/typetests/provider.tsx b/test/typetests/provider.tsx new file mode 100644 index 000000000..f6cbc263c --- /dev/null +++ b/test/typetests/provider.tsx @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ + +import React from 'react' +import { Provider } from '../../src' +import { Store } from 'redux' + +declare const store: Store<{ foo: string }> + +function App() { + return ( + + foo + + ) +} From 9e09869307f829273d8a38a452d814a546b692b0 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 6 Oct 2022 16:34:13 +0100 Subject: [PATCH 3/3] `any` -> `unknown` --- src/components/Provider.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Provider.tsx b/src/components/Provider.tsx index e3340355d..f3ffb2da1 100644 --- a/src/components/Provider.tsx +++ b/src/components/Provider.tsx @@ -4,7 +4,7 @@ import { createSubscription } from '../utils/Subscription' import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect' import { Action, AnyAction, Store } from 'redux' -export interface ProviderProps { +export interface ProviderProps { /** * The single Redux store in your application. */ @@ -24,7 +24,7 @@ export interface ProviderProps { children: ReactNode } -function Provider({ +function Provider({ store, context, children,