作者:沙楽33 | 来源:互联网 | 2022-12-02 16:39
1> Per Svensson..:
您应该始终在Component类上使用泛型声明props和state对象。any
尽可能避免使用关键字。
提示:现代化的IDE允许您F12并检查定义文件,如果您是TypeScript的新手,那将是一个很大的帮助。您还可以在DT GitHub存储库上阅读React定义,此处定义了React.Component
type AppProps = {}
type AppState = {}
class App extends React.Component {
constructor(props: AppProps) {
super(props);
//this.props will already be of type AppProps.
//Only the constructor props are any
}
public render() {
return (
Go Type React
);
}
}