原文:typescript報錯:Object is possibly 'null' 請問怎么解決?

這么寫是不行的嗎 請問應該怎么寫呢 readonly state fold: true, answer: null render return this.state.answer amp amp this.state.answer.content 最佳答案 readonly state: any fold: true, answer: null 如果未能解決,請移步:ts報錯:Object is ...

2020-12-05 13:05 0 1392 推薦指數:

查看詳情

解決typescript:error TS2531: Object is possibly 'null'.問題

原因是什么呢?是ts編譯器在編譯時診斷到document.getElementById('test')可能會為null,所以給出了這樣一個提示:對象可能為null解決方式是這樣: 加一個!,感嘆號什么意思呢,它其實是not null 的斷言操作符,不執行運行時檢查,告訴編譯器只需要 ...

Sun Jan 02 04:57:00 CST 2022 0 1599
TS2532: Object is possibly 'undefined'.

報錯代碼: //定義請求攔截器 service.interceptors.request.use( (config) => { if (window.localStorage.Token && window.localStorage.Token.length ...

Tue Mar 22 00:50:00 CST 2022 0 1187
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM