简体   繁体   English

function 的正确 typescript 类型是什么

[英]What is the correct typescript type for the function

I just started with the TS.What class should I set for the onGetData in the interface. TS刚入手,界面中的onGetData应该设置什么class。 Because as I know, any cannot be left in the code因为据我所知,任何不能留在代码中

interface Props {
  onGetData: any;
}

class TSSS extends Component<Props> {
  componentDidMount() {
    this.props.onGetData();
  }

  render() {
    return <div></div>;
  }
}

export default connect((dispatch: any) => ({
  onGetData: () => {
    dispatch(getUsersData());
  },
}))(TSSS);

maybe you can use : Function as the type in interface so the code will be:也许您可以使用: Function作为接口类型,因此代码将是:

interface Props {
  onGetData: Function;
}

class TSSS extends Component<Props> {
  componentDidMount() {
    this.props.onGetData();
  }

  render() {
    return <div></div>;
  }
}

export default connect((dispatch: any) => ({
  onGetData: () => {
    dispatch(getUsersData());
  },
}))(TSSS);

or, if you are using visual studio code, you can hover into your function onGetData to see what the type data of the function is, and select that copy and paste into your interface Props of onGetData或者,如果您使用的是 visual studio code,您可以将 hover 放入您的 function onGetData以查看 function 的类型数据是什么,并将 select 复制并粘贴到您的onGetData interface Props

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM