我正在开发一个使用 TypeScript 和 React 的项目,我对这两个项目都很陌生。我的问题是关于 TypeScript 中的接口以及它与props和状态的关系。实际发生了什么?除非我声明接口props和状态,否则我的应用程序根本不会运行,但我通过 React 构造函数使用状态,并且我已经看到所有这些信息都将进入“interface MyProps”或“interface MyStates”的示例. 以这段代码为例:
"use strict";
import * as React from 'react'
import NavBar from './components/navbar.tsx'
import Jumbotron from './components/jumbotron.tsx';
import ContentPanel from './components/contentPanel.tsx';
import Footer from './components/footer.tsx';
interface MyProps {}
interface MyState {}
class Root extends React.Component <MyProps, MyState>  {
  constructor(props) {
    super(props);
    this.state = {
      ///some stuff in here
  
    };
  }
  render() {
    return (
      <div>
        <NavBar/>
        <Jumbotron content={this.state.hero}/>
        <ContentPanel content={this.state.whatIs}/>
        <ContentPanel content={this.state.aboutOne}/>
        <ContentPanel content={this.state.aboutTwo}/>
        <ContentPanel content={this.state.testimonial}/>
        <Footer content={this.state.footer}/>
      </div>
    )
  }
}
export default Root;
(我已经删除了 this.state 中的内容只是为了在这里发布)。为什么需要接口?这样做的正确方法是什么,因为我认为我正在以 JSX 方式而不是 TSX 方式考虑这一点。