Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the improvements in TypeScript 2.0?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the improvement of TypeScript 2.0. it is very detailed and has a certain reference value. Friends who are interested must finish it!

Microsoft recently released TypeScript 2.0, which provides simplified declaration file acquisition, Non-nullable types, and Readonly modifiers.

Daniel Rosenwasser, TypeScript project manager, said his team was "excited" that the release "follows the ECMAScript specification, provides broader support for JavaScript libraries and tools, and provides a best-in-class editing experience in major editors through a language service."

TypeScript 2.0 makes it easier for developers to access and use declaration files. Rosenwasser acknowledges that "learning how to obtain and manage dependencies on declaration files" has been the biggest headache for users in the past, but in version 2.0, the scope package @ types/lodash can be installed with the command npm install-- save @ types/lodash, and then TypeScript 2.0 will be able to reference it automatically when Lodash is imported anywhere in the developer's program.

The Non-nullable type is another new feature introduced in version 2.0. Although the language originally envisioned that all types would always be Nullable, the team actually found that such a design did not prevent null/undefined problems. In this release, both null and undefined have their own types, allowing developers to make it clear when null/ undefined values are acceptable. The following video shows this feature of TypeScript.

Insert a video: https://msdnshared.blob.core.windows.net/media/2016/09/nonnullable-types-fade.mp4

Attributes in TypeScript 2.0 can be declared read-only, and then all Get-accessor that does not contain Set-accessor are considered read-only.

Class Person {readonly name: string; constructor (name: string) {if (name.length < 1) {throw new Error ("Empty name!");} this.name = name;}} / / Error! 'name' is read-only.new Person ("Daniel"). Name = "Dan"

The whole community spoke highly of the new version released by Microsoft. Ed Rochenski expressed his opinion in the HackerNews report:

I can't wait to use these new features in our production applications. TypeScript has always been my bridge into JavaScript development. IMHO JavaScript has long been abandoned. I don't know if I can continue to use JavaScript to develop without TypeScript.

Non-nullable types, tagged Union types, and simpler declaration files are the most exciting features in the new release.

In Rosenwasser's blog post, user Allen asked through comments: "I'd love to use strictNullChecks in my code base, but is there any way to get some / all library type definitions to continue to use lax null checking?" He is said to have encountered problems using strictNullChecks with external type definitions because the type definitions of the libraries used are not strictly Null safe.

Rosenwasser responded: "currently you need to create dependencies for strictNullChecks, and although many third-party .d.ts files can be used unaffected, if you encounter problems, you can send a Pull request to the DefinitelyTyped of the types-2.0 branch at any time."

According to the roadmap, TypeScript also supports Spread and Rest for ES8 object properties, Decorator for function expression / arrow functions, and node registration hooks. A complete list of improvements and changes since TypeScript 1.8 can be accessed on the project's GitHub page.

These are all the contents of this article entitled "what are the improvements in TypeScript 2.0?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report