javascript - Using TypeScript with jQuery the Reference file does not exist - Stack Overflow

I created my first TypeScript file using the VS2012 plugin and web essentials:<reference path=�

I created my first TypeScript file using the VS2012 plugin and web essentials:

///<reference path='/Scripts/jquery/jquery.d.ts' />
/*jslint browser: true*/
/*jslint vars: true */
/*global $, jQuery*/
/*global ajaxOnFailure, doAddSubmit, doResetTabs*/
/*global mvcOnFailure, updateGridMeta*/

function alertWin(title, message) {
    $.modal({
        content: '<p class="align-center">' + message + '</p>',
        title: title,
        minWidth: 150,
        maxWidth: 900,
        maxHeight: 600,
        width: false,
        buttons: {
            'Ok': function (win) { win.closeModal(); }
        }
    });
}

I dragged and dropped the reference file from the solution to the top of the file and it does exist.

However as soon as it's dragged I get a red line under it saying "referenced file does not exist". I also note that it does not seem to recognize the $ in my script.

Here's my directory structure:

/Scripts
/jquery/jquery.d.ts
/Shared/dialog/functions/file1.ts <-- the file above

Note:

When I put the .ts file in the same directory as file1.ts and reference as follows then it works:

///<reference path='jquery.d.ts' />

So my question is:

How can I have my jquery.d.ts in just the one place and reference it from my files?

I created my first TypeScript file using the VS2012 plugin and web essentials:

///<reference path='/Scripts/jquery/jquery.d.ts' />
/*jslint browser: true*/
/*jslint vars: true */
/*global $, jQuery*/
/*global ajaxOnFailure, doAddSubmit, doResetTabs*/
/*global mvcOnFailure, updateGridMeta*/

function alertWin(title, message) {
    $.modal({
        content: '<p class="align-center">' + message + '</p>',
        title: title,
        minWidth: 150,
        maxWidth: 900,
        maxHeight: 600,
        width: false,
        buttons: {
            'Ok': function (win) { win.closeModal(); }
        }
    });
}

I dragged and dropped the reference file from the solution to the top of the file and it does exist.

However as soon as it's dragged I get a red line under it saying "referenced file does not exist". I also note that it does not seem to recognize the $ in my script.

Here's my directory structure:

/Scripts
/jquery/jquery.d.ts
/Shared/dialog/functions/file1.ts <-- the file above

Note:

When I put the .ts file in the same directory as file1.ts and reference as follows then it works:

///<reference path='jquery.d.ts' />

So my question is:

How can I have my jquery.d.ts in just the one place and reference it from my files?

Share Improve this question edited Oct 26, 2012 at 9:13 Fenton 252k73 gold badges402 silver badges410 bronze badges asked Oct 26, 2012 at 5:50 user1679941user1679941
Add a ment  | 

2 Answers 2

Reset to default 5

You need to use reference path relative to the script using it (with..) – you can't just ask to calculate from root.

See this answer Using jQuery plugin in TypeScript

The issue with jQuery plugins (and other plugin based libraries) is that you not only do you need a library.d.ts file for the base library you also need a plugin.d.ts file for each plugin. And somehow thes plugin.d.ts files need to extend the library interfaces defined in the library.d.ts files. Fortunately, TypeScript has a nifty little feature that lets you do just that.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745462384a4628767.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信