gpt4 book ai didi

angular - 错误 TS2304 : Cannot find name 'X' in the app. angular 4 项目的 components.ts 和 main.ts 文件

转载 作者:太空狗 更新时间:2023-10-29 17:40:31 26 4
gpt4 key购买 nike

typescript 的新手。使用 neovim、ubuntu 16.04 和各种 vim typescript 插件 tsuquyomileafgarland/typescript-vimmhartington/nvim-typescript,我很确定我正确配置了它们。

我已经成功安装了@angular/cli,我正在尝试完成教程,但是我遇到了一个我不明白的错误。

`1 .._modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts|| TS2304: Cannot find name 'Iterable'. 
2 ../node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts|| TS2304: Cannot find name 'Map'.
3 ../node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts|| TS2304: Cannot find name 'Map'.
4 ../node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts|| TS2304: Cannot find name 'Iterable'.
5 damn/node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts|| TS2304: Cannot find name 'Map'.
6 ..//node_modules/@angular/core/src/di/reflective_provider.d.ts|| TS2304: Cannot find name 'Map'.
7 ../node_modules/@angular/core/src/di/reflective_provider.d.ts|| TS2304: Cannot find name 'Map'.
8 ../node_modules/rxjs/Observable.d.ts|| TS2693: 'Promise' only refers to a type, but is being used as a value here.`

我尝试了所有我猜的,从

尝试以下 tsconfig filesGlob 属性:

"filesGlob": [ "main.ts", "typings.d.ts", "app/**/*.ts", "!app/**/*.spec.ts" ],

安装 angular/core-js 和 @types/core-js 和 typings

npm install --save-dev @types/core-js
npm install @types/node --save

编辑后的 ​​tsconfig.json 文件

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"types": ["node"],
"typeRoots": [
"node_modules/@types"
],
"files": [
"main.ts",
"typings.d.ts"
],
"filesGlob": [
"main.ts",
"typings.d.ts",
"app/**/*.ts"
],
"lib": [
"es2016",
"dom"
]
}
}

我还编辑了 tsconfig.app.json 文件

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": [],
"typeRoots": [
"../node_modules/@types/"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}

但是,尽管有所有这些更改,错误仍然存​​在于我的 app.components.ts 文件和 main.ts 中。

最佳答案

"skipLibCheck": true 添加到 tsconfig.json 中的 "compilerOptions"

关于angular - 错误 TS2304 : Cannot find name 'X' in the app. angular 4 项目的 components.ts 和 main.ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45224319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com