typescript報錯:Object is possibly 'null' 請問怎麼解決?

這麼寫是不行的嗎?請問應該怎麼寫呢?

`

readonly state = {
    fold: true,
    answer: null
};

render () {
    return (
        
{ this.state.answer && this.state.answer.content }
) } `

 

最佳答案

 

readonly state: any = {
    fold: true,
    answer: null
};

如果未能解決,請移步:ts報錯:Object is possibly 'null' 詳解

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章