报错信息如下
node_modules/@angular/core/src/application_init.d.ts(17,27): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(116,76): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(132,110): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(162,67): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(164,101): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,16): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(32,16): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts(15,48): error TS2304: Cannot find name 'Iterable'.
node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts(23,18): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,123): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,165): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/linker/compiler.d.ts(43,49): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/compiler.d.ts(51,65): error TS2304: Cannot find name 'Promise'.主要意思说是map,promise找不到,这2个对象是es6才有的,如果改成编译成es6,就不报错。
查找了很多资料,也试了很多方法。
最终
target: "es5", //es3 for IE8 and below
lib: ["es2016", "dom"], //加上这个就可以解决该问题
本文解决了在使用 Angular 时遇到的 TypeScript 编译错误问题,主要原因是缺少必要的类型定义。通过调整 TypeScript 的配置文件(tsconfig.json),指定目标版本为 es5 并引入 es2016 和 dom 库,成功解决了 Promise 和 Map 类型未定义的问题。
929

被折叠的 条评论
为什么被折叠?



