Microsoft has released a new thing--typescript

Source: Internet
Author: User
Keywords Microsoft Javascript typescript

Today, Microsoft releases a new thing--typescript, the project's main head is Anders Hejlsberg (c++#, the father of Turbopascal), which can help http://www.aliyun.com/zixun/ Aggregation/33906.html ">javascript developers easier to write and maintain" application-scale"apps, I quickly researched and toyed with it, and found that it was different from many similar projects in the past, and these differences made typescript more practical and competitive.

From here you can see a Anders Hejlsberg yourself to introduce Typescript's films:

Completely based on JavaScript syntax
Because JavaScript syntax (strictly speaking ECMAScript 262 3/e or 5/e) does not have a perfect solution for typing (data type), there are some eyebrows angles that are familiar with several programming languages (e.g. C/s, Java, C # And so on) habits are different, so to use JavaScript to develop large applications, there must be a very careful specification and developers must have a deep understanding of JavaScript "good/ugly/awful parts" (reference: Javascript:the good Parts).

So there are all sorts of things that project wants to improve on (refer to a list of people here), most often referred to as GWT (Google Web Toolkit), script#, or coffeescript, all of which want to mitigate The burden of JavaScript developers is to develop applications using some well-formed or easier language (GWT is Java, script# is C # and Coffeescript is a custom syntax), and then through their respective compilers (compiler) to produce JavaScript program code. These projects have their own pros and cons, as well as their markets (reducing the cost of language conversion), and at first glance Typescript seems to be doing something similar, but it's different from the project mentioned above: it's completely compatible with JavaScript's original syntax. That is, if you used to happen to be a JavaScript developer, you could continue to write the program without changing the way you wrote JavaScript in the past, like the typescript online example:

function greeter {return ' Hello, ' + person;}


var user = "Jane user";


Document.body.innerHTML = greeter (user);

This code, which you can store as sample1.ts, and then compile it through the typescript compiler, and eventually produce exactly the same JavaScript program code, shows that it is fully compatible with JavaScript syntax, It also proves that it is possible to continue to integrate the existing JavaScript libraries (such as jQuery, YUI, etc.), which are other projects relatively rare practices.

So as long as it is writing JavaScript environment (browser, NODEJS) can use typescript.

Add Strong type
So what good is typescript to JavaScript developers? Its most important task is to add the syntax of the strong type (fervent typing) in the language, not only to enable developers to write more rigorous programs using these grammars, It's also easier to get other tools to do program code analysis-like it's easier to optimize the program code or the Syntax hints (Intellisense) feature in the Program code Editor.

Next we can learn how typescript joins strong types by using a code example:

interface Person {firstname:string; lastname:string;


function Greeter (person:person) {return "Hello," + Person.firstname + "" + Person.lastname;}


var user = {firstname: "Jane", LastName: "User"};


Document.body.innerHTML = greeter (user);

Related Article

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.