Reactjs 从Javascript>Typescript转换React+Axios

Reactjs 从Javascript>Typescript转换React+Axios,reactjs,typescript,axios,Reactjs,Typescript,Axios,我正试图将Chris Coyier的这个非常有用的代码笔从JS翻译成TS,并遇到了一些问题 早期使用Typescript,不确定要使用哪个类扩展声明 我得到了一个属性或签名。ts1131 on const th=如下所示 不确定这是否是我定义类extend for React声明的方式,因为通常在TS中,声明此常量时不需要extend React调用 interface Props { } interface State { } class App extends React.Compon

我正试图将Chris Coyier的这个非常有用的代码笔从JS翻译成TS,并遇到了一些问题

早期使用Typescript,不确定要使用哪个类扩展声明

我得到了一个属性或签名。ts1131 on const th=如下所示

不确定这是否是我定义类extend for React声明的方式,因为通常在TS中,声明此常量时不需要extend React调用

interface Props {
}

interface State { 
}

class App extends React.Component<Props, State>{
    function1 : () => { }
    function2 : () => { 
      const th = this;
      this.serverRequest = 
          axios.get(this.props.source).then(function(result) {    
              th.setState({ jobs: result.data.jobs});
              })    
    }
}
function1:=>{}语法对对象文字有效,对类无效。如果是箭头,则应该是TypeScript,也称为JavaScript类字段

const th=当可以使用箭头时,此配方已过时

应该是:

class App extends React.Component<Props, State>{
    function1 = () => { }

    function2 = () => { 
      this.serverRequest = axios.get(this.props.source).then((result) => {    
          this.setState({ jobs: result.data.jobs});
      })    
    }
    ...
}