tsd-improve IDE's ability to intelligently perceive JavaScript

Source: Internet
Author: User

The most painful thing about writing the front-end JavaScript code is the IntelliSense of the Code (Intelli sense).

Chasing its root cause is because JavaScript is a weak type of dynamic language. For weakly typed dynamic languages, IntelliSense is a "soft rib" for IDE tools. IntelliJ, such as IDE's IntelliSense approach, is a compromise: full-text search, and then show the object members that have been used. The disadvantage of this approach is that its ability to intelligently perceive is not accurate and often shows a lot of extraneous code hints.

In many modern development methods, the powerful support of the IDE and the modular organization of this "engineering" thinking is one of the ways we deal with large-scale development, which has been recognized by the industry. So in the last two years, the JavaScript world has also proposed a large-scale development program, including Google's Dart and Microsoft's typescript. With Angular2.0 gave up his own dart, and chose Typescript, also marked the gradual maturity of typescript. Typescript is a new language designed by Microsoft's General architect Anders Hejlsberg, a legendary figure in the software world and a designer for Delphi and. Net. Typescript is a language that can be compiled into traditional JavaScript, which does not completely create a new language, and Typescript is a superset of the JavaScript language, and its greatest feature is the introduction of type systems. And after compiling as a JavaScript file, you can output the type metadata information of ". Ts", which provides an important basis for the intelligent perception and refactoring of our IDE.

More knowledge about typescript, here the author is not in the narrative too much. Interested readers can go to http://www.typescriptlang.org/to learn, this sectionto, is another feature of it: it compiles the output of the metadata information file ( *.d.ts ), it can not need to modify the original JavaScript files in the case, While adding metadata type information to JavaScript, these types of information can assist the IDE, giving intelligent hints and the basis for refactoring.

In the open source community of typescript, this kind of template file has been implemented for many third-party libraries, and we can quickly apply them to our projects. Of course, the amount of the third party contained in our common: Angular, jQuery, underscore, lodash, Jasmine and so on.

The official also provided us with a handy tool called TSD (full name: TypeScript Definition Manager for definitelytyped), which is the idea of using NPM package management tools to implement a similar package management tool, We don't need any learning costs, just use it like NPM.

Here is the TSD homepage: http://definitelytyped.org/tsd/, where you can learn more about it, or whether the template library you need exists in the TSD repository.

TSD is also a nodejs tool, so it's very easy to install it, just enter it on the command line (for some Linux users you need sudo):

npm install tsd -g

Installing the template Library We need is also simple, such as jquery and angular installation:

tsd install jquery angular --save

This will help us download the d.ts file for jquery and angular and store it in the Typings standalone subdirectory of the current directory, and it will save the dependent information we need in a file called Tsd.json, like the Package.json of NPM, to facilitate our version management, And the sharing between teams. We only need to share this Tsd.json file to other colleagues, and then

tsd install

Everything is ready to be satisfied.

The format of the Tsd.json file is as follows:

At the same time, the TSD tool will also produce a tsd.d.ts file for us in the typing directory, which will introduce these template files for us, enabling the IDE to recognize such template files:

/// <reference path="angularjs/angular.d.ts" />/// <reference path="jquery/jquery.d.ts" />

Here are the IntelliSense graphs we get in IntelliJ:

The tools currently available to support the typescript feature are: IntelliJ family, Microsoft home vs Tools, Sublime. With the tool of TSD, we may not be able to try the typescript feature yet, but we can still use it to help our common JavaScript development.

tsd-improve IDE's ability to intelligently perceive JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.