简体   繁体   English

为什么我的 React / TypeScript 应用程序会产生编译错误?

[英]Why is my React / TypeScript app generating a compile error?

I've downloaded the following app (which works in the sandbox):我已经下载了以下应用程序(在沙箱中工作):

https://codesandbox.io/s/wbkd-react-flow-forked-78hxw4 https://codesandbox.io/s/wbkd-react-flow-forked-78hxw4

Locally, after I run:在本地,我运行后:

npm install

and then接着

npm start

I get the following error:我收到以下错误:

TypeScript error in /wbkd-react-flow-forked/src/components/ErrorBoundary.tsx(6,15):
Parameter 'props' implicitly has an 'any' type.  TS7006

    4 | 
    5 | export class ErrorBoundary extends Component {
  > 6 |   constructor(props) {
      |               ^
    7 |     super(props);
    8 |     this.state = { hasError: false };
    9 |   }

How do I resolve the compile error?如何解决编译错误?

Add typing to your props:为你的道具添加打字:

type ErrorBoundaryProps = {
  someProps: boolean;
}

export class ErrorBoundary extends Component<ErrorBoundaryProps> {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管 TypeScript 编译器错误,为什么我的 React Native 应用程序构建成功? - Why does my React Native app build successfully despite TypeScript compiler error? 为什么我的 React 应用程序总是无法编译? - Why Does My React App Keep Failing To Compile? 由于 ESLint 错误,我的 create-react-app 无法编译 - My create-react-app is failing to compile due to ESLint error 如何解决“ create-react-app my-app”未生成my-app项目并显示错误的问题? - How to resolve “create-react-app my-app” not generating my-app project and shows error? 为我的反应打字稿组件库生成/维护打字稿定义文件 - Generating/Maintaining a typescript definition file for my react typescript component library 为什么`npx create-react-app my-app --typescript` 不给我打字稿 bo - Why doesn't `npx create-react-app my-app --typescript` give me typescript bo 在我的 React 应用程序中使用 redux 调度出现 TypeScript 错误 - Getting a TypeScript error with redux dispatch in my React app 为什么我在此React / Typescript应用程序中收到no exported member错误? - Why am I getting the no exported member error in this React/Typescript app? “编译失败”“解析错误:意外的令牌:”在尝试迁移到现有 create-react-app 中的 typescript 期间 - "Failed to Compile" "Parsing error: Unexpected token :" during attempt to migrate to typescript in existing create-react-app 为什么 create-react-app 在尝试 eslint 时会给出 typescript 错误(尽管没有 typescript 文件)? - Why is create-react-app giving typescript error when trying to eslint (though no typescript files)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM