jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了TS-2304错误 – 在“.ts”文件中导入“jquery”时,在TypeScript中找不到名称“Iterable”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Visual studio Code作为编辑器处理TypeScript版本2.4.我使用以下命令在NPM上安装了jQuery:

npm install --save @types/jquery

然后我从GitHub下载了jquery模块的源代码.

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上编译代码时,我收到以下错误

请提出适当的解决方案.

解决方法

tsconfig.json的配置是正确的.当目标设置为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文件.

希望能帮助到你.

大佬总结

以上是大佬教程为你收集整理的TS-2304错误 – 在“.ts”文件中导入“jquery”时,在TypeScript中找不到名称“Iterable”全部内容,希望文章能够帮你解决TS-2304错误 – 在“.ts”文件中导入“jquery”时,在TypeScript中找不到名称“Iterable”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。