当前位置: 代码迷 >> 综合 >> error TS2583: Cannot find name ‘WeakMap‘. Do you need to change your target library? Try changing th
  详细解决方案

error TS2583: Cannot find name ‘WeakMap‘. Do you need to change your target library? Try changing th

热度:81   发布时间:2023-12-12 01:02:49.0

error TS2583: Cannot find name ‘WeakMap’. Do you need to change your target library? Try changing the lib compiler option to es2015 or later.

problem

test.ts中包含使用 WeakMap,
执行tsc test.ts 时报错:

error TS2583: Cannot find name 'WeakMap'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.  

reason

原因是 WeakMap 是 es6 的语法

solution

在命令行显示加上 lib
tsc --lib "es2015","dom" test.ts

  相关解决方案