简体   繁体   English

带有 Typescript jquery 问题的原子

[英]Atom with Typescript jquery issue

I'm having several issues whilst attempting to begin editing a large workplace project using GitHub's Atom Editor with Typescript instead of Visual Studio.我在尝试使用 GitHub 的 Atom 编辑器和 Typescript 而不是 Visual Studio 开始编辑大型工作场所项目时遇到了几个问题。

  1. My JavaScript functions are not recognized unless I convert all of my JavaScript to .ts files, my system has 100+ JS files of which ideally I would like to leave as is, is it possible to to develop new files in TypeScript whilst leaving all my old JS files as is, without the editor complaining the functions do not exist?除非我将所有 JavaScript 文件转换为.ts文件,否则我的 JavaScript 函数无法识别,我的系统有 100 多个 JS 文件,理想情况下我想保持原样,是否可以在 TypeScript 中开发新文件,同时保留我所有的旧的 JS 文件,没有编辑器抱怨功能不存在?

  2. jQuery apparently does not exist, We use aspx pages and a Site.Master template file which define the jQuery location using jQuery 显然不存在,我们使用aspx页面和Site.Master模板文件来定义 jQuery 位置使用

    <script src="/scripts/jquery-latest.min.js"></script>

I'm guessing the Atom Editor cannot understand the site master page and therefore does not think jQuery exists.我猜 Atom 编辑器无法理解站点母版页,因此认为 jQuery 不存在。 This is holding back development any easy way to get this recognized?这是阻碍开发的任何简单方法来获得认可?

项目布局图

Note: This isn't a node project or anything complicated, simply a bunch of HTML(.aspx) pages with a bunch of JS files注意:这不是一个节点项目或任何复杂的东西,只是一堆带有一堆 JS 文件的 HTML(.aspx) 页面

You don't need to convert any of your js files, but anywhere you want to use one of your JavaScript functions from another file, you need to do an ambient declaration like this:您不需要转换任何 js 文件,但是在任何地方您想使用另一个文件中的 JavaScript 函数之一,您都需要执行如下环境声明:

declare var myFunction: any;

This lets TypeScript know that there's some function named myFunction available for you to use, and don't worry about it's type, just let me use it however I want.这让 TypeScript 知道有一些名为myFunction的函数可供您使用,不用担心它的类型,让我随心所欲地使用它。 You could do the same for jQuery, but there are type definition files for popular libraries like jQuery, so you can get the TypeScript intellisense for them.你可以对 jQuery 做同样的事情,但是有像 jQuery 这样的流行库的类型定义文件,所以你可以为它们获取 TypeScript 智能感知。 You can install them with Typings .您可以使用Typings安装它们。 It's a command line tool that for installing type definition files.它是一个用于安装类型定义文件的命令行工具。 Once you have Typings installed, run the following command to install the jQuery definition file:安装 Typings 后,运行以下命令来安装 jQuery 定义文件:

typings install jquery --ambient --save

If you're using Visual Studio 2015, you can also use the Package Installer , which supports installing type definition files with Typings.如果您使用的是 Visual Studio 2015,还可以使用Package Installer ,它支持使用 Typings 安装类型定义文件。 It doesn't install Typings for you though.不过,它不会为您安装 Typings。 You have to install it yourself first.您必须先自己安装它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM