TypeScript 常見錯誤與解決方案


1、TS1005、TS2004

ERROR in [at-loader] ./node_modules/@types/d3-dsv/index.d.ts:493:52   TS1005: ',' expected. ERROR in [at-loader] ./node_modules/@types/d3-dsv/index.d.ts:159:51   TS2304: Cannot find name 'readonly'.

 

 問題原因:
  typescript版本太低,需要升級到最新版本

 解決方案:

  報錯時的版本是3.3.3,升級到4.2.3后,報錯消失

 

 

 

2、TS2308

ERROR in [ at-loader ] ./node_modules@types/d3/index.d.ts:26:1

  TS2308: Module 'd3-array' has already exported a member named 'map' .  Consider explicitly re-exporting to resolve the ambiguity.

ERROR in [ at-loader ] ./node_modules@types/d3/index.d.ts:26:1

  TS2308: Module 'd3-array' has already exported a member named 'map' .  Consider explicitly re-exporting to resolve the ambiguity.

問題原因:

  兩個文件都導出了同一個名為map的方法,所以ts檢測報錯

解決方案:

  項目的tsconfig.json中,配置編譯選項,skipLibCheck設為true。忽略所有的聲明文件( *.d.ts)的類型檢查。

 

 

3、TS2339

ERROR in [ at-loader ] ./src/wave-artboard/wave-artboard.tsx:233:12

  TS2339: Property 'event' does not exist on type 'typeof import("F:/eFlowerProject.BSR-H5/node_modules/@types/d3/index")'.

ERROR in [ at-loader ] ./src/wave-artboard/wave-artboard.tsx:233:12
   TS2339: Property 'event' does not exist on type 'typeof import("F:/eFlowerProject.BSR-H5/node_modules/@types/d3/index")'.

問題原因:

  項目中使用d3.event從而報錯

解決方案:

  將d3.event 改成 d3[event]

 

 

跳轉typescript官方文檔請點這https://www.tslang.cn/docs/handbook/nightly-builds.html


免責聲明!

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



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