TypeScript知識:Property 'xxx' does not exist on type 'never'.


一、報錯提示:Property 'xxx' does not exist on type 'never'.

  開發過程中出現這個錯誤是因為Typescript在執行代碼檢查時在該對象沒有定義相應屬性,這個錯誤不致命,遇到該錯誤有以下幾種解決辦法。

1、將對象設置成 any

this.targetArray = this.options.find((item:any) => { return item.articleId == val; });

2、通過字符方式獲取對象屬性

this.targetArray = this.options.find((item) => { return item["articleId"] == val; });

3、聲明斷言,強制執行

this.targetArray = this.options.find((item) => { return (item as any).articleId == val; });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM