I'm writing a react application using Typescript and in my render method I have this error:
Object is possibly null
The thing is that I am already checking if the object is not null. Here is my code:
interface State {
tutorial: any;
}
export default class Tutorial extends PureComponent<any, State> {
state = {
tutorial: null,
};
componentDidMount() {
loadTutorial(this.props.match.params.id).then((res: any) => {
this.setState({ tutorial: res.tutorial });
});
}
render() {
if (this.state.tutorial === null) return null;
return (
<section>
<h1>Tutorial: {this.state.tutorial.title}</h1>;
</section>
);
}
}
But I still have the error in the render method. How can I solve it?