【发布时间】:2017-10-02 15:47:54
【问题描述】:
更新
不需要导入。相反,我需要添加对文件顶部的引用。所以我的 WebAPI.js 的第一行应该是 /// <reference path ="../typings/jquery/jquery.d.ts"/> 而不是 import { $ } from '../jquery-3.1.1';
我正在尝试导入 jQuery 以在 Typescript 文件中使用,但我尝试的所有操作都会收到各种错误。我遵循了here 和here 的解决方案,但没有任何运气。
tsconfig.json
{
"compilerOptions": {
"removeComments": true,
"preserveConstEnums": true,
"out": "Scripts/CCSEQ.Library.js",
"module": "amd",
"sourceMap": true,
"target": "es5",
"allowJs": true
}
WebAPI.js
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
【问题讨论】:
-
你安装了打字机吗?
npm install --save-dev @types/jquery -
@Rens 我有来自 NuGet 的
typings/jquery/jquery.d.ts文件。是一样的吗? -
@Rens 是的,我做到了
标签: javascript jquery ajax typescript import