Oli*_* H. 13 iterable typescript angular
我正在使用Typescript 2.4.1并在我的项目中升级了许多包.其中我将Angular从2升级到4.3.1.在@types包中进行了许多更正之后,我留下的错误是:
\node_modules\@types\jquery\index.d.ts(2955,63): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(767,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(771,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(775,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(779,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(783,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(787,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(791,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(795,24): error TS2304: Build:Cannot find name 'Iterable'.
\node_modules\@types\three\three-core.d.ts(799,24): error TS2304: Build:Cannot find name 'Iterable'.
Run Code Online (Sandbox Code Playgroud)
我找到了许多类似的问题和答案,目前的解决方案是针对"es2015"和/或添加lib:["dom","es2015","es2015.iterable"].我已经尝试了所有这些以及更多,但仍然留下相同的'Iterable'错误.
我更新的tsconfig.json是这样的:
{
"compileOnSave": true,
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "dom", "dom.iterable", "es2015", "es2015.iterable", "esnext" ],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noEmitOnError": true,
"outDir": "./wwwroot/js",
"removeComments": false,
"rootDir": "./Client",
"sourceMap": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es2015",
"typeRoots": [
"./node_modules/@types",
"./Client"
]
},
"exclude": [
"node_modules",
"wwwroot/lib"
],
"filesGlob": [
"./Client/**/*.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我的package.json是:
{
"version": "1.0.0",
"name": "web-server",
"private": true,
"dependencies": {
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/router": "^4.3.1",
"@angular/upgrade": "^4.3.1",
"bootstrap": "3.3.7",
"core-js": "2.4.1",
"lodash": "4.17.4",
"pixi.js": "4.5.4",
"reflect-metadata": "0.1.10",
"rxjs": "^5.4.2",
"systemjs": "0.20.17",
"three": "0.86.0",
"zone.js": "0.8.14"
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/jquery": "3.2.9",
"@types/lodash": "4.14.71",
"@types/mocha": "2.2.41",
"@types/pixi.js": "4.5.2",
"@types/three": "0.84.19",
"bower": "^1.8.0",
"gulp": "3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.1",
"gulp-typescript": "^3.2.1",
"gulp-inline-ng2-template": "^4.0.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-tsc": "^1.3.2",
"gulp-uglify": "^3.0.0",
"merge2": "^1.1.0",
"path": "^0.12.7",
"rimraf": "^2.6.1",
"systemjs-builder": "^0.16.9",
"typescript": "2.4.1"
},
"scripts": {
"gulp": "gulp",
"rimraf": "rimraf",
"bundle": "gulp bundle",
"postbundle": "rimraf dist"
}
}
Run Code Online (Sandbox Code Playgroud)
在所有这些lib包含之后,怎么没有找到"iterable"?Typescript编译器不会忽略我的tsconfig.json,因为更改某些选项会提供各种输出,但没有错误.
我的环境是使用Typescript Tools 2.4.1的Visual Studio 2015更新3.我正在使用npn @types(没有打字).详细编译输出显示Visual Studio有效地使用2.4.1版本.
而最奇怪的是使用gulp进行编译使用相同的Typescript版本和tsconfig没有错误.
Wil*_*ill 19
'Iterable'在节点的typing文件中定义.安装解决了我的问题的文件(node_modules/@types/node/index.d.ts).
npm install @types/node --save-dev
Run Code Online (Sandbox Code Playgroud)
Ben*_*ler 15
这看起来很像这里描述的内容:
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16939
所以要么尝试使用
"target": "es6"
Run Code Online (Sandbox Code Playgroud)
如上所述 - 或者对我们有用的东西:
"target": "es5",
"lib": ["es2016","dom"]
Run Code Online (Sandbox Code Playgroud)
升级我的整个环境,而不是项目,就成功了。我升级到 VS2017,现在一切都可以正常编译。
尽管我重新安装了除 VS2015 之外的几乎所有内容,但我的安装可能存在损坏。
感谢大家的帮助。