TypeScript定义文件应该包含在_references.js中吗? [英] Should TypeScript definition files be included in _references.js?

查看:108
本文介绍了TypeScript定义文件应该包含在_references.js中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我包含一个Nuget包 jquery.TypeScript.DefinitelyTyped ,是否应该添加为 Scripts / _references.js 的引用?如果是这样,是否可以删除 jQuery ,或者特别说, jquery-2.1.1.js 来自Scipts目录的文件?也就是说,当TypeScript可用时,我是否需要普通的.js nuget包?



在更广泛的背景下,我在想这个过程在Visual Studio 2013中使用最新更新工作或者可能是首选的工作方式或什么样的工作方式。我发现许多关于TypeScript工具之前的方法的博客文章和教程都包含在Visual Studio中。



< edit:看起来很可能会让很多其他资源与Javascript库,如图片和CSS文件。因此,看起来, .js 文件和可选的 d.ts 文件都是必需的。但是 d.ts 文件应该包含在 _references.js 中,还是包含在中。 js d.ts 文件?

解决方案

< blockquote>

说,我是否包含一个Nuget包jquery.TypeScript.DefinitelyTyped,它是否应该作为对Scripts / _references.js的引用添加?


只要您的项目中有 jquery.d.ts 就足够了。定义文件不会在任何已编译的javascript输出中结束(请参阅使用_references.ts 获取更多细节。)



编辑:重申一下,因为我刚刚意识到你是谈论 _references.js 而不是 _references.ts ...添加 .js < intellisense不需要/ code>文件和 .d.ts 。项目中 jquery.d.ts 对于VS 2013中的智能感知已经足够了。


是否可以从Scipts目录中删除jQuery,或者特别是jquery-2.1.1.js文件?


不,不要删除 jquery.js 文件。来自DefinitelyTyped的nuget包只是一个定义文件。定义文件不提供任何功能,只需描述形状图书馆。它允许人们使用现有的JavaScript库以及类型约束的额外好处 - 而无需在TypeScript中单独重写和维护库。



例如,假设我有一个包含以下代码的JavaScript库:

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

描述此JavaScript库的定义文件可能如下所示:

 声明var myAlert:(text:string)=>无效; 

如你所见,我的定义文件中没有任何功能,所以两者都是使用我的JS所必需的TypeScript中的库(请注意,生产代码中只需要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?

解决方案

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).

这篇关于TypeScript定义文件应该包含在_references.js中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆