I am working on TypeScript version 2.4 using Visual Studio Code as an editor. I installed jQuery with NPM using the following command:
npm install --save @types/jquery
Then I downloaded the source code of jquery module
from GitHub.
The code of registrationpage.ts
file is as follows:
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();
}
}
The code for index.html
is as follows:
<!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
file :
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"lib": [ "es2015", "dom" ]
}
}
When I compile the code on CMD , I get the following error:
ERROR TS2304 : cannot find the name Iterable
Please suggest an appropriate solution.
The configuration of tsconfig.json
is correct. When the target is set to ES5
and libraries : es2015,es2015-iterable
are included then Iterable
is supported.
The point is when we compile the .ts file by command tsc "filename"
then "tsconfig.json" is ignored by the compiler. Also, while working with external modules, you need to include the following js
files to support module loading:
https://unpkg.com/core-js/client/shim.min.js">
https://unpkg.com/[email protected]/dist/system.src.js
Lastly, Compile the file with this command
**tsc -p .**
This command will not ignore tsconfig.json
file.
Hope it helps.
Consider installing the node type definitions.
npm i --save-dev @types/node
If you are using Yarn instead of NPM:
yarn add -D @types/node
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With