首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将JQuery导入到Typescript文件?

如何将JQuery导入到Typescript文件?
EN

Stack Overflow用户
提问于 2017-05-04 20:46:31
回答 4查看 64.2K关注 0票数 32

更新

不需要导入。相反,我需要在文件的顶部添加一个引用。所以我的WebAPI.js的第一行应该是/// <reference path ="../typings/jquery/jquery.d.ts"/>而不是import { $ } from '../jquery-3.1.1';

我正在尝试导入jQuery以在Typescript文件中使用,但我在尝试任何操作时都收到了各种错误。我遵循了herehere的解决方案,但没有任何运气。

tsconfig.json

代码语言:javascript
复制
{
    "compilerOptions": {
        "removeComments": true,
        "preserveConstEnums": true,
    "out": "Scripts/CCSEQ.Library.js",
    "module": "amd",
        "sourceMap": true,
    "target": "es5",
    "allowJs": true
}

WebAPI.js

代码语言:javascript
复制
import { $ } from '../jquery-3.1.1';

export class ExpenseTransaction extends APIBase {

    constructor() {
        super();
    }

    Get(): void {
        let expenses: Array<Model.ExpenseTransaction>;
        let self = this;
        $.ajax({
            url: this.Connection,
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            success: function (data: any): void {
                expenses = self.ConvertToEntity(data.value);
            },
            error: function (data: any): void { console.log(data.status); }
        });
    };
}

我也尝试过import * as $ from '../jquery.3.1.1'

错误

  • Module jquery-3.1.1 has no exported member $
  • Property ajax does not exist on type (selector: any, context: any) => any
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43783307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档