Should TypeScript definition files be included in _references.js?

Let's say I include the jquery.TypeScript.DefinitelyTyped Nuget package , should I add it as a reference to Scripts/_references.js

? And if so, is it possible to remove jQuery or say a file jquery-2.1.1.js

from the Scipts directory? That is, would I need a simple .js nuget package when TypeScript is available?

In a broader context, I think about how this process works or what might be the preferred way of working or what works in Visual Studio 2013 with the latest updates. Many of the blog posts and tutorials I find in detail about pre-TypeScript methods have been included in Visual Studio.

<edit: it looks like a lot of other resources could have been provided with Javascript libraries like images and css files. So it would seem that files are needed, .js

and possibly files d.ts

. But should the file d.ts

be included in, _references.js

or perhaps the file .js

and d.ts

?

+3


source to share


1 answer


Let's say I include the jquery.TypeScript.DefinitelyTyped Nuget package, should it be added as a reference to Scripts / _references.js?

As long as you have it jquery.d.ts

in your project, it will be good enough. The definition file doesn't end up in any compiled javascript output (see _references.ts for more details ).

Edit: just to reiterate since I understood what you are talking about _references.js

, not _references.ts

... adding a file .js

and .d.ts

not required for intellisense. Having jquery.d.ts

in a project is good enough for intellisense in VS 2013.

Is it possible to remove jQuery, or say jquery-2.1.1.js file from Scipts directory?

No, don't delete the file jquery.js

. The nuget package from DefinitelyTyped is just a definition . Definition files have no functionality and simply describe the form of the library . This allows people to use existing JavaScript libraries with the added benefit of type constraints - without having to rewrite and maintain the library separately in TypeScript.



For example, let's say I have a JavaScript library that contains the following code:

function myAlert(text) {
    alert(text);
}

      

The definition file describing this JavaScript library might look like this:

declare var myAlert: (text: string) => void;

      

As you can see, there is no functionality in my definition file, so both are required to use my JS library in TypeScript (note that in production code only the JS file is required, because that is the one that the browser will execute).

+1


source







All Articles