In one of the codes in react documentation, the value defined in this.state is used in render() as
{this.state.name}
But when I implement that react code using typescript, it is giving error as:-
Property 'age' does not exist on type 'Readonly<{}>'.
The code in the typescript is:-
import * as React from "react";
class App2 extends React.Component{
constructor(props:any)
{
super(props)
this.state = {
age : 0,
name : "rohit"
};
}
public render()
{
return(
<h1>
{this.state.name}
</h1>
)
}
}
export default App2;