【发布时间】:2018-01-04 11:32:56
【问题描述】:
我正在使用 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 />
<input id="submit" type="button" value="Submit" />
</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
请提出适当的解决方案。
【问题讨论】:
-
你找到解决办法了吗,我也有同样的问题
-
我在 VS 2017 UI 中遇到了同样的问题。从你下面的回答听起来好像 tsconfig.json 被忽略了?你能提供更多细节吗?如何解决这个问题?
-
是的,它忽略了 tsconfig.json 文件。解决方案是使用命令编译代码:“tsc -p”。请参考:“typescriptlang.org/docs/handbook/tsconfig-json.html”
标签: jquery node.js typescript npm