Javascript React道具不会在Custom Next.js应用程序组件中继承

Javascript React道具不会在Custom Next.js应用程序组件中继承,javascript,reactjs,typescript,next.js,Javascript,Reactjs,Typescript,Next.js,我创建了自定义的next.jsApp组件作为一个类(旨在通过初始化Google analytics覆盖componentDidMount函数) 我面临的问题是 错误TS2339:MyApp类型上不存在属性“props” props字段应从定义为以下内容的App组件继承: export default class App<P = {}, CP = {}, S = {}> extends React.Component<P & AppProps<CP>, S&

我创建了自定义的next.js
App
组件作为一个类(旨在通过初始化Google analytics覆盖
componentDidMount
函数)

我面临的问题是
错误TS2339:MyApp类型上不存在属性“props”

props
字段应从定义为以下内容的
App
组件继承:

export default class App<P = {}, CP = {}, S = {}> extends React.Component<P & AppProps<CP>, 
S> {
    static origGetInitialProps: typeof appGetInitialProps;
    static getInitialProps: typeof appGetInitialProps;
    componentDidCatch(error: Error, _errorInfo: ErrorInfo): void;
    render(): JSX.Element;
}
导出默认类App扩展React.Component{
静态OrigetinalProps:appGetInitialProps的类型;
静态getInitialProps:appGetInitialProps的类型;
componentDidCatch(错误:error,_errorInfo:errorInfo):void;
render():JSX.Element;
}
为什么编译器抱怨
MyApp
组件上缺少
props
字段?它不应该继承自扩展
React.component
App
组件吗

使用版本:

  • 打字稿4
  • Next.js 10.0.0
  • 反应17.0.0
  • @类型/反应17.0.0

    • 要使用
      this.props
      ,props应该是myApp类中的一个方法。因此,
      this.props
      不存在,因为编译器发出信号

      您需要在
      tsconfig.json
      文件中的
      编译器选项下添加
      esModuleInterop:true


      我还建议您使用
      “jsx”:“preserve”
      ,以避免其他与React相关的问题。

      这是正确的。谢谢为什么要添加它?我只从6.1.2升级了next.js版本。到10.0.0。除此之外什么也没做。
      {
          "compilerOptions": {
              "module": "commonjs",
              "target": "es5",
              "lib": ["es5", "es2015.promise", "dom"],
              "noImplicitAny": true,
              "noImplicitReturns": true,
              "strictNullChecks": true,
              "suppressImplicitAnyIndexErrors": true,
              "removeComments": true,
              "preserveConstEnums": true,
              "sourceMap": true,
              "jsx": "react",
              "baseUrl": ".",
              "skipLibCheck": true,
              "paths": {
                  "@myapp/*": ["./node_modules"]
             }
         }
      }
      
      export default class App<P = {}, CP = {}, S = {}> extends React.Component<P & AppProps<CP>, 
      S> {
          static origGetInitialProps: typeof appGetInitialProps;
          static getInitialProps: typeof appGetInitialProps;
          componentDidCatch(error: Error, _errorInfo: ErrorInfo): void;
          render(): JSX.Element;
      }