0

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?

Fenton
  • 241,084
  • 71
  • 387
  • 401

2 Answers2

5

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

Oleg Mihailik
  • 2,514
  • 2
  • 19
  • 32
  • I am starting to notice that. However I also see many examples that don't use relative path. Is that just for non asp-mvc ? –  Oct 26 '12 at 07:37
0

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.

Community
  • 1
  • 1
Kao
  • 2,242
  • 3
  • 22
  • 31
  • Thanks for the link but it does not help me when it comes to specifying the location of the library.d.ts. I can only seem to reference these if they are in the same directory as the library file. –  Oct 26 '12 at 06:04