类型“从不”打字稿/反应上不存在属性

kja*_*amp 4 javascript typescript reactjs

当我尝试在 React 中运行我的代码时,我收到“属性 'activationDate' 不存在于类型 'never'' 错误,这会是什么问题?我确定它与打字稿有关。

编辑:仍然对导师类型有任何问题吗?不知道这是什么意思?

第二次编辑:作为参考,我正在按照本教程(https://alligator.io/react/axios-react/)进行简单的 GET 请求,我只是不知道如何将其转换为打字稿。

const TOKEN_KEY:string = `mpp-tk`;

type mentor = { activationDate: any }


class SamSearch extends React.Component<any>  {

  public state = {
    mentors: mentor[] // or any[]
  }

public componentDidMount() {
    const token = localStorage.getItem(TOKEN_KEY);
  const config = {
    headers: {
      Authorization : token
    }
  }

axios.get(`http://localhost:8080/findMentorFromSam/001339159`, config)
  .then(res => {
    console.log(res.data);
    const mentors = res.data;
    this.setState({ mentors });
  })


 }



public render(): React.ReactNode {
    const {
      classes
    } = this.props as any & {
      titleComponent?: React.Component
    };
return (

  <Grid container className={classes.test}>
  <ul>
  { this.state.mentors.map(mentor => <li>{mentor.activationDate}</li>)}
  </ul>
  <p>TEST</p>
  </Grid>



   )
  }
}
export default compose(
  withRouter,
  withStyles(styles)
)(SamSearch)
Run Code Online (Sandbox Code Playgroud)

Dan*_*rez 5

你得说数组导师是什么类型的,应该是这样的

type Mentor = { activationDate: any }

class SamSearch extends React.Component<any>  {
  public state: { mentors: Mentor[] } = { // or any[]
    mentors: []
  }
  // ...rest of the class
}
Run Code Online (Sandbox Code Playgroud)