• 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

  • 相关阅读:
    理解消息循环和窗口过程(转)
    对话框和控件编程(转)
    俄罗斯方块
    男生女生配(抽屉原理)
    翻转吧,字符串
    数塔
    Pseudoprime numbers伪素数(快速幂+判定素数)
    shǎ崽 OrOrOrOrz
    As Easy As A+B
    求素数(筛选法)
  • 原文地址:https://www.cnblogs.com/liuxuande/p/14634521.html
Copyright © 2020-2023  润新知