import React from "react";

interface MyComponentProps {
    hasError?: boolean;
    children?: React.ReactNode;
  }
  
  interface MyComponentState {
    hasError: boolean;
  }
  
  class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
    constructor(props: MyComponentProps) {
      super(props);
      this.state = {
        hasError: false, // 初始值
      };
    }
  
    render() {
      // 现在你可以安全地访问 this.state.hasError
      return <div>{this.state.hasError ? 'Error' : this.props.children}</div>;
    }
  }
  
  export default MyComponent