【发布时间】:2020-01-01 11:02:54
【问题描述】:
我正在为 React 实现状态管理。我正在使用 Next.js 和 Typescript。
我使用了下一个 redux 包装器,并按照指南的指示在 /pages/_app.js 上有以下内容。
import React from "react";
import {createStore} from "redux";
import {Provider} from "react-redux";
import App, {Container} from "next/app";
import withRedux from "next-redux-wrapper";
import configureStore from '../state/store';
class MyApp extends App {
static async getInitialProps ({Component, ctx}) {
return {
pageProps: (Component.getInitialProps ? await Component.getInitialProps(ctx) : {})
}
}
render() {
const {Component, pageProps, store} = this.props;
return (
<Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
);
}
}
export default withRedux(configureStore)(MyApp);
我尝试在 render() 函数中声明的 store 变量出现打字稿错误,这会引发如下错误:
const store: any
Property 'store' does not exist on type 'Readonly<AppInitialProps & { Component: NextComponentType<NextPageContext, any, {}>; router: Router; }> & Readonly<{ children?: ReactNode; }>'.ts(2339)
我不确定问题是什么。我无法访问任何类型/接口以允许 store 成为变量。这很有趣,因为这是许多开发人员在使用 Typescript/Redux/Next.js 时的解决方案。
任何帮助/指针将不胜感激,谢谢。
【问题讨论】:
标签: reactjs typescript react-redux next.js