更新
不需要导入。相反,我需要在文件的顶部添加一个引用。所以我的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
https://stackoverflow.com/questions/43783307
复制相似问题