📜 ⬆️ ⬇️

TypeScript and the path to version 2.0

var t: [number, string] = [1, "hello"]; t = []; // Error t = [1]; // Error t = [2, "test"]; // Ok t = ["test", 2]; // Error t = [2, "test", true]; // Ok 

When we released TypeScript 1.0 earlier this year, we focused on creating a language that will help developers really scale their JavaScript projects. It was quite fascinating to see what people did with it, including 170,000 lines of code in the Mozilla Shumway , Walmart stationery and our rich experience with Microsoft Azure , in which we jumped over a million lines of code.

Our goal with TypeScript is to continue to support projects of a similar scope and make it the best language for scaling JavaScript. With version 1.1, we released a fast and lightweight compiler that can produce a result four times faster than the previous one. The new compiler is also more flexible in terms of adding new functionality than we will certainly use, moving to version 2.0.

Today we want to talk about our plans for the second version. We invite you to join our TypeScript page on GitHub and help us make TypeScript even better.

The Growth of the JavaScript Typing Community


The JavaScript typing community continues to grow; we are happy to watch it and be part of it. DefinitelyTyped today contains over 700 .d.ts of typed descriptions for a wide range of libraries and frameworks and is approaching to break the bar of 600 contributors.
')
We also see new projects growing on the basis of the work done by the JavaScript typing community. The first of these, Facebook's Flow language, announced earlier this year. It is based on modules, as a fundamental building block for applications, and adds to them a rich typed interface and compatibility with .d.ts. The second project, called AtScript, was recently announced by the Angular team at Google. It is based on annotations of types similar to TypeScript, and adds annotations to meta-data and validation during execution.

The TypeScript team works with both commands (Flow and AtScript) to ensure that resources already created by the JavaScript typing community can be used in these tools. All projects can learn a lot from each other, we look to the future to work together to create the best tools for the JavaScript community. In the long term, we also strive to ensure that the best features of these tools are also included in ECMAScript, the standard behind JavaScript.

Road map


TypeScript 1.3


Our next release will be TypeScript 1.3, it will include a new rewritten language service that allows you to make the development process in code editors faster and smoother. It will also be the first release in which we will begin standardizing the compiler's API, so the tools will be able to fully rely on it. As part of this release, we will also show a preview of the new version of integration in Visual Studio, which will later become part of it.

From the point of view of the language, we add two new features: protected and type tuples (tuple) . The secure access modifier has been one of the most frequently requested features for quite a while; we are pleased to add additional object-oriented patterns to TypeScript. With type tuples, we are starting to expand the type system to synchronize with practices that will be based on the capabilities of the upcoming ECMAScript 6. If it is more specific, this will allow the use of type-safe destructuring of types considered as tuples.

Perhaps you are asking: “Where is TypeScript 1.2?” We expected to use it as a release to stabilize the previous version, but version 1.1. turned out to be stable enough for the developers to switch to it. This allowed us to proceed to the completion of work on the language service and the addition of new features earlier than we originally planned.

TypeScript 1.4


In release 1.4 we want to focus on the further development of the language. The first new features are already available in the master vertek on GitHub. These include type combinations and the use of typeof in if-blocks to specify types. Both possibilities are shown in the example below:

 function createCustomer(name: { firstName: string; lastName: string } | string) { if (typeof name === "string") { // Because of the typeof check in the if, we know name has type string return { fullName: name }; } else { // Since it's not a string, we know name has // type { firstName: string; lastName: string } return { fullName: name.firstName + " " + name.lastName }; } } // Both customers have type { fullName: string } var customer = createCustomer("John Smith"); var customer2 = createCustomer({ firstName: "Samuel", lastName: "Jones" }); 

Together, these features allow you to use more natural templates when working with JavaScript code. Combining types, allowing you to more accurately describe types with multiple variants, also helps to mitigate some pain points of earlier versions of TypeScript that arose when working with mixed arrays.

From TypeScript 1.5 to TypeScript 2.0


Looking to the future for release 2.0, we are focused on two goals in addition to the main goal to provide the best tools for JavaScript development. The first is to dock with ES6. Synchronization with ES6 will allow TypeScript to become a superset of the next version of JavaScript, opening up the possibility of working on new patterns and code creation practices, including destructuring, string patterns, promises, iterators, etc., in addition to the features that TypeScript already supports, for example, classes and lambda -functions Second, we also work with Flow and Angular to make sure TypeScript is the best language for working with a wide range of libraries, including declarative frameworks like the upcoming Angular 2.0 release.

Looking to the future


There is a lot of work ahead, but we are already well on our way. You can try some of the features mentioned above by taking the latest source in our TypeScript repository on GitHub . We adopted the GitHub style for laying out specifications along with the use of pull queries. This will allow you to track new features as they are developed, and we will also be happy to hear your feedback.

useful links


Source: https://habr.com/ru/post/241744/


All Articles