我正在尝试用我的react应用程序为Jest测试设置一个redux提供程序。
import {ReactNode} from 'react'
import {Provider} from 'react-redux'
import {store} from "../redux/reducer/store";
type PropsWithOptionalChildren<P = unknown> = P & { children?: ReactNode };
type RootState = ReturnType<typeof store>
interface ReduxProviderProps extends PropsWithChildren {
store: RootState,
}
const ReduxProvider = ({children, store}: ReduxProviderProps) => <Provider store={store}>{children}</Provider>
export default ReduxProvider
字符串
然后我就像这样
test("...", () => {
const store = configureStore();
const wrapper = ({ children }) => (
<ReduxProvider reduxStore={store}>{children}</ReduxProvider>
);
...
});
型
但是,编译器会对下面的代码行发出抱怨
type RootState = ReturnType<typeof store>
型
类型[...]不满足约束(...args:any)=> any类型[...]未提供签名的匹配项(...args:any):any
这是store
变量
export const store = configureStore({
reducer: persistedReducer,
devTools: process.env.NODE_ENV !== 'production',
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: false
}).concat(apiSlice.middleware),
});
型
和附加信息
export const rootReducer = combineReducers({
a: aReducer,
b: bReducer,
[apiSlice.reducerPath]: apiSlice.reducer,
})
const config = getPersistConfig({
key: 'root',
storage,
blacklist: ['a'],
rootReducer
})
const persistedReducer = persistReducer(config, rootReducer)
型
如何解决编译器错误?
2条答案
按热度按时间ffscu2ro1#
试试这个:
字符串
tuwxkamq2#
将RootState类型更改为如下所示,并查看它是否解决
第一个月