Вы должны всегда объявлять свои реквизиты и объекты состояния с обобщениями в классе Component.По возможности воздержитесь от использования ключевого слова any
.
Совет. Современная среда IDE позволяет выполнить F12 и просмотреть файл определения, что очень полезно, если вы новичок в TypeScript.Вы также можете прочитать определение React в репозитории DT GitHub, React.Component определены здесь
type AppProps = {}
type AppState = {}
class App extends React.Component<AppProps, AppState> {
constructor(props: AppProps) {
super(props);
//this.props will already be of type AppProps.
//Only the constructor props are any
}
public render() {
return (
<div className="App">
<h1>Go Type React</h1>
</div>
);
}
}