Skip to content

Commit 726d0d1

Browse files
authored
Add type to useWrappedStore returned props (#501)
* Add type to useWrappedStore returned props
1 parent 8e098f7 commit 726d0d1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/wrapper/src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import App, {AppContext, AppInitialProps} from 'next/app';
1+
import App, {AppContext, AppInitialProps, AppProps} from 'next/app';
22
import React, {useEffect, useMemo, useRef} from 'react';
33
import {Provider} from 'react-redux';
44
import {Store} from 'redux';
@@ -211,10 +211,10 @@ export const createWrapper = <S extends Store>(makeStore: MakeStore<S>, config:
211211
};
212212

213213
// giapState stands for getInitialAppProps state
214-
const useWrappedStore = (
215-
{initialState: giapState, initialProps, ...props}: any,
216-
displayName = 'useWrappedStore',
217-
): {store: S; props: any} => {
214+
const useWrappedStore = <P extends AppProps>(incomingProps: P, displayName = 'useWrappedStore'): {store: S; props: P} => {
215+
// createWrapper adds WrapperProps to incomingProps, they are not present in P so type needs to be coerced here
216+
const {initialState: giapState, initialProps, ...props} = incomingProps as P & WrapperProps;
217+
218218
// getStaticProps state
219219
const gspState = props?.__N_SSG ? props?.pageProps?.initialState : null;
220220
// getServerSideProps state

0 commit comments

Comments
 (0)