TS-2304错误 – 在“.ts”文件中导入“jquery”时,在TypeScript中找不到名称“Iterable”

我正在使用Visual Studio Code作为编辑器使用TypeScript 2.4版本。 我使用以下命令安装了带有NPM的jQuery:

npm install --save @types/jquery 

然后我从GitHub下载了jquery module的源代码。

registrationpage.ts文件的代码如下:

 import * as $ from 'jquery'; class Registration_Page { txtuname: string; Registration() { $('#table').hide; this.txtuname = ( <HTMLTextAreaElement> (document.getElementById('txtusername'))).value; } } window.onload = () => { $('#table').show; var bttnLogin = document.getElementById('submit'); var obj = new Registration_Page(); bttnLogin.onclick = function () { obj.Registration(); } } 

index.html的代码如下所示:

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="registrationpage.js"></script> </head> <body> <form id="form1"> <div> <fieldset style="font-size: medium; color: #000000;"> <legend style="background-color:#CCCCFF; font-size: larger;font-weight:bold">Registration Page in TypeScript</legend> <br /> <b>UserName</b> <input id="txtusername" type="text" /><br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input id="submit" type="button" value="Submit" />&nbsp;&nbsp;&nbsp;&nbsp; </fieldset> </div> <div id="table"> <table> <tr> <th>UserName</th> </tr> </table> </div> </form> </body> </html> 

tsconfig.json文件:

 { "compilerOptions": { "target": "es5", "noImplicitAny": true, "lib": [ "es2015", "dom" ] } } 

当我在CMD上编译代码时,出现以下错误:

错误TS2304:找不到名称Iterable

请提出适当的解决scheme。

tsconfig.json的configuration是正确的。 当目标设置为ES5和库: es2015,es2015-iterable被包括时,则支持Iterable 。 关键是当我们通过命令tsc "filename"编译.ts文件时,编译器会忽略“tsconfig.json”。 另外,在使用外部模块时,您需要包含以下js文件以支持模块加载:

 https://unpkg.com/core-js/client/shim.min.js"> https://unpkg.com/systemjs@0.19.39/dist/system.src.js 

最后,用这个命令编译文件

 **tsc -p .** 

这个命令不会忽略tsconfig.json文件。

希望能帮助到你。

考虑安装节点types定义。

npm i --save-dev @types/node

如果您使用而不是NPM

yarn add -D @types/node