Veksi
Veksi

Reputation: 3758

Should TypeScript definition files be included in _references.js?

Say, I include a Nuget package jquery.TypeScript.DefinitelyTyped, should it be added as a reference to Scripts/_references.js? And if so, should it be possible to remove jQuery, or specifically, say, jquery-2.1.1.js file from the Scipts directory? That is to say, would I have a need for plain .js nuget packages when a TypeScript one is available?

In a broader context, I'm thinking how this process works or what could be the preferred way of working or what shoud work in Visual Studio 2013 with the latest updates. Many of the blog posts and tutorials I find elaborate on methods before TypeScript tooling was included within Visual Studio.

<edit: It looks like that one could let a lot of other resources with Javascript libraries, like pictures and css files. So, it would seem, both the .js file and optionally a d.ts files would be needed. But should the d.ts file be included in _references.js or perhaps both the .js and d.ts file?

Upvotes: 3

Views: 1034

Answers (1)

David Sherret
David Sherret

Reputation: 106650

Say, I include a Nuget package jquery.TypeScript.DefinitelyTyped, should it be added as a reference to Scripts/_references.js?

As long as you have the jquery.d.ts in your project that will be good enough. The definition file doesn't end up in any compiled javascript output (see using _references.ts for more detail).

Edit: Just to reiterate since I just realized you're talking about _references.js and not _references.ts... adding the .js file and .d.ts is not necessary for intellisense. Having jquery.d.ts in the project is good enough for intellisense in VS 2013.

Should it be possible to remove jQuery, or specifically, say, jquery-2.1.1.js file from the Scipts directory?

No, don't remove your jquery.js file. The nuget package from DefinitelyTyped is simply a definition file. Definition files offer no functionality and simply describe the shape of a library. It 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, say I have a JavaScript library that contains the following code:

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

A definition file that describes this JavaScript library might look like this:

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

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

Upvotes: 1

Related Questions