我在尝试
$(function(){
alert('Hello');
});
Run Code Online (Sandbox Code Playgroud)
它在Visual Studio中显示此错误:(TS) Cannot find name '$'..如何在TypeScript中使用jQuery?
无需导入.相反,我需要添加对文件顶部的引用.所以我的WebAPI.js的第一行应该是/// <reference path ="../typings/jquery/jquery.d.ts"/>而不是import { $ } from '../jquery-3.1.1';
我试图导入jQuery以在Typescript文件中使用,但我收到的各种错误与我尝试的一切.我按照这里和这里的解决方案,但没有任何运气.
{
"compilerOptions": {
"removeComments": true,
"preserveConstEnums": true,
"out": "Scripts/CCSEQ.Library.js",
"module": "amd",
"sourceMap": true,
"target": "es5",
"allowJs": true
}
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud)